Our website is made possible by displaying online advertisements to our visitors.Please consider supporting us by disabling your ad blocker.
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Translate it in your own Language

Print this Job Post

Print Friendly and PDF

Tuesday, May 27, 2014

Collection Interview Questions

Question-131:What is difference between ArrayList and Vector?
Answer:

ArrayList:


  1. ArrayList is not synchronized.
  2. ArrayList is not a legacy class
  3. ArrayList increases its size by 50% of the array size.

Vector:

  1. Vector is synchronized.
  2. Vector is a legacy class. 
  3. Vector increases its size by doubling the array size. 

Question-132: What is difference between ArrayList and LinkedList?
Answer:

ArrayList:


  1. ArrayList uses a dynamic array
  2. ArrayList is not efficient for manipulation because a lot of shifting is required.

Linked List: 

  1.  LinkedList uses doubly linked list. 
  2.  LinkedList is efficient for manipulation.


Question-133: What is difference between HashMap and Hashtable? 
Answer:

HashMap:


  1. HashMap is not synchronized. 
  2. HashMap can contain one null key and multiple null values.

Hashtable:

  1. Hashtable is synchronized. 
  2. Hashtable cannot contain any null key nor value. 


Question-135: What is hash-collision in Hashtable and how it is handled in Java?
Answer:
Two different keys with the same hash value. Two different entries will be kept in a single hash bucket to avoid the collision.


Question-136: What is difference between HashSet and HashMap?
Answer:
HashSet contains only values whereas HashMap contains entry(key,value).


Question:137: What is difference between HashMap and TreeMap?
Answer:

HashMap:


  1. HashMap is can contain one null key. 
  2. HashMap maintains no order.

TreeMap:


  1. TreeMapconnot contain any null key.
  2. TreeMap maintains ascending order.



Question-138:What is difference between HashSet and TreeSet?
Answer:
HashSet maintains no order whereas TreeSet maintains ascending order.


Question-142: What is difference between List and Set?
Answer:
List can contain duplicate elements whereas Set contains only unique elements.


Question-143: What is difference between Iterator and ListIterator?
Answer:
Iterator traverses the elements in forward direction only whereas ListIterator traverses the elements in forward and backward direction.


Question-144: Can you make List,Set and Map elements synchronized?
Answer:
Yes, Collections class provides methods to make List,Set or Map elements as synchronized: public static List synchronizedList(List l){}
public static Set synchronizedSet(Set s){}
public static SortedSetsynchronizedSortedSet(SortedSet s){} 
public static Map synchronizedMap(Map m){}
public static SortedMapsynchronizedSortedMap(SortedMap m){}


Question-145: What is difference between Iterator and Enumeration?
Answer:

Iterator:


  1. Iterator can traverse legacy and non-legacy elements.
  2. Iterator is fail-fast.
  3. Iterator is slower than Enumeration.

Enumeration:


  1. Enumeration can traverse only legacy elements.
  2. Enumeration is not fail-fast.
  3. Enumeration is faster than Iterator. 



Question-146: What is difference between Comparable and Comparator?
Answer:

Comparable:


  1. Comparable provides only one sort of sequence. 
  2. It provides one method named compareTo().
  3. It is found in java.lang package. 
  4. If we implement Comparable interface, actual class is modified. 

Comparator:


  1. Comparator provides multiple sort of sequences. 
  2. It provides one method named compare().
  3. it is found in java.util package.  
  4. Actual class is not modified. 



Question-147: What is the Dictionary class?
Answer:
The Dictionary class provides the capability to store key-value pairs.

Miscellaneous Interview Questions


1 comment:

Copyright @ CrackMNC 2014-2024
Divas Nikhra Theme by Crack MNC