Select chapter



basics (7.papers)
constructors (1.papers)
packages (1.papers)
inheritance (7.papers)
misc (3.papers)
exceptions (5.papers)
threads (4.papers)
overloading (1.papers)
jsp (3.papers)
servlets (9.papers)
jdbc (2.papers)
util (1.papers)
xml (2.papers)
IO stream (3.papers)
Hide

Sponsored Links


  

java interview questions and answers

Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
9
What is the difference between array and arraylist?
  1. Array is a fixed length data structure while ArrayList is a variable length Collection class.
  2. There are no predefined functions on array like add(), remove() etc. Where as ArrayList contains numerous utility functions.
  3. both are true
  4. none
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
11
Difference between arraylist vs vector?
  1. ArrayList is part of collection framework but vector is not part of collection framework.
    ArrayList is not synchronized but vector is synchronized.
    
  2. both arraylist and vector are dynamically growable.
  3. If there is not sufficient space to insert a new element, then arraylist will grow by the double the size of previous size where vector will grow only by half of the previous size.
  4. all are true.
Show Answer
Share Facebook gmail Twitter
12
How to convert arraylist to array?
  1. ArrayList<String> list = new ArrayList<String>();
         
    list.add("India");
    list.add("Switzerland");
    list.add("Italy");
    list.add("France");
     
    String [] countries = list.toArray(new String[list.size()]);
  2. ArrayList<String> items = new ArrayList<String>();
    
    items.add("home");
    items.add("about us");
    items.add("products");
    items.add("contact us");
    String[] arrItems = new String[items.size()];
    
    arrItems = items.toArray(stockArr);
    
  3. assume that list is arraylist of elements.
    
    String[] arr = list.toArray(new String[list.size()]);
    
  4. all options are correct
Show Answer
Share Facebook gmail Twitter
13
Example of arraylist in Java?
  1. public class ArrayListExample {
    
     
     public static void main(String[] args) {
      String strnew;
      ArrayList<String> list = new  ArrayList<String>();
            list.add("1");
            list.add("2");
            list.add("3");
            list.add("4");
            list.add("5");
            list.add("6");
        System.out.println(list);           
    }
    }
    
  2. public class ArrayListExample {
    
     
     public static void main(String[] args) {
      String strnew;
      ArrayList<String> list = new  ArrayList<String>();
            list.put("1");
            list.put("2");
            list.put("3");
            list.put("4");
            list.put("5");
            list.put("6");
        System.out.println(list);           
    }
    }
    
  3. public class ArrayListExample {
    
     
     public static void main(String[] args) {
      String strnew;
      ArrayList<String> list = new  ArrayList<String>();
            list.insert("1");
            list.insert("2");
            list.insert("3");
            list.insert("4");
            list.insert("5");
            list.insert("6");
        System.out.println(list);           
    }
    }
    
  4. none
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
20
Can't I convert ArrayList into synchronized ArrayList?
  1. No, if you want synchronized then go for Vector.
  2. Yes by using Collections.synchronizedList function
  3. none
Show Answer
Share Facebook gmail Twitter
Read more papers :