Question-181. What is the difference between Iterator and Enumeration ?

Answer-

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

 

Question-182. What is the difference between List and Set ?

Answer- List can contain duplicate elements whereas Set contains only unique elements.

Question-183. What is the difference between HashSet and TreeSet ?

Answer- HashSet maintains no order whereas TreeSet maintains ascending order.

Question-184. What is the difference between Set and Map ?

Answer- Set contains values only whereas Map contains key and values both.

Question-185. What is the difference between HashSet and HashMap ?

Answer- HashSet contains only values whereas HashMap contains entry(key,value). HashSet can be iterated but HashMap need to convert into Set to be iterated.

Question-186. What is the difference between HashMap and TreeMap ?

Answer- HashMap maintains no order but TreeMap maintains ascending order.

Question-187. What is the difference between HashMap and Hashtable ?

Answer-

HashMap Hashtable
1) HashMap is not synchronized. 1) Hashtable is synchronized.
2) HashMap can contain one null key and multiple null values. 2) Hashtable cannot contain any null key or null value.

 

Question-189. What is the difference between Collection and Collections ?

Answer- Collection is an interface whereas Collections is a class. Collection interface provides normal functionality of data structure to List, Set and Queue. But, Collections class is to sort and synchronize collection elements.

Question-190. What is the difference between Comparable and Comparator ?

Answer-

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