Question-131:What is difference between ArrayList and Vector?
Answer:
Question-132: What is difference between ArrayList and LinkedList?
Answer:
Question-133: What is difference between HashMap and Hashtable?
Answer:
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:
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:
Question-146: What is difference between Comparable and Comparator?
Answer:
Question-147: What is the Dictionary class?
Answer:
The Dictionary class provides the capability to store key-value pairs.
Answer:
ArrayList:
- ArrayList is not synchronized.
- ArrayList is not a legacy class
- ArrayList increases its size by 50% of the array size.
Vector:
- Vector is synchronized.
- Vector is a legacy class.
- Vector increases its size by doubling the array size.
Question-132: What is difference between ArrayList and LinkedList?
Answer:
ArrayList:
- ArrayList uses a dynamic array
- ArrayList is not efficient for manipulation because a lot of shifting is required.
Linked List:
- LinkedList uses doubly linked list.
- LinkedList is efficient for manipulation.
Question-133: What is difference between HashMap and Hashtable?
Answer:
HashMap:
- HashMap is not synchronized.
- HashMap can contain one null key and multiple null values.
Hashtable:
- Hashtable is synchronized.
- 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:
- HashMap is can contain one null key.
- HashMap maintains no order.
TreeMap:
- TreeMapconnot contain any null key.
- 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:
- Iterator can traverse legacy and non-legacy elements.
- Iterator is fail-fast.
- Iterator is slower than Enumeration.
Enumeration:
- Enumeration can traverse only legacy elements.
- Enumeration is not fail-fast.
- Enumeration is faster than Iterator.
Question-146: What is difference between Comparable and Comparator?
Answer:
Comparable:
- Comparable provides only one sort of sequence.
- It provides one method named compareTo().
- It is found in java.lang package.
- If we implement Comparable interface, actual class is modified.
Comparator:
- Comparator provides multiple sort of sequences.
- It provides one method named compare().
- it is found in java.util package.
- Actual class is not modified.
Question-147: What is the Dictionary class?
Answer:
The Dictionary class provides the capability to store key-value pairs.
Thanks for sharing this useful information Java Collection interview questions .
ReplyDelete