Q31. Explain about HashSet class?
Q32. If we are trying to insert duplicate values in Set what will happen?
If we are trying to insert duplicate objects to the HashSet , we wont get any compile time or run time errors just the add(Object o) returns false and it doesn’t add that object.
Q33. What is LinkedHashSet?
It is the child class of HashSet. The main difference between HashSet and LinkedHashSet is:
In the case of HashSet insertion order is not preserved , but in the case of LinkedHashSet insertion will be preserved.
Q34. Differences between HashSet and LinkedHashSet?
HashSet |
LinkedHashSet |
| 1The Underlying datastructure is Hashtable | 1The underlying datastructure is combination of LinkedList and Hashtable |
| 2Insertion Order is not preserved | 2 Insertion order is preserved. |
| 3Introduced in 1.2 version | 3 Introduced in 1.4 version |
Q35. What are major enhancements in 1.4 version of collection frame work?
LinkedHashSet
LinkedHashMap
IdentityHashMap
Q36. Explain about TreeSet?
It is Collection object which can be used to represent a group of objects according to some sorting order.
Q37. What are differences between List and Set interfaces?
List |
Set |
| 1Insertion Order is preserved | 1Insertion Order is not preserved |
| 2Duplicate Objects are allowed | 2 Duplicate Objects are not allowed |
| 3The implemented classes are ArrayList,LinkedList , Vector and Stack classes | 3 The implemented classes are HashSet, LinkedHashSet and Tree |
Q38. What is Comparable interface?
Q39. What is Comparator interface?
Q40. What are differences between Comparable and Comparator?
Comparable |
Comparator |
| 1This can be used for natural sorting order | 1This can be used for implementing customized sorting |
| 2This interface present in java.lang package | 2 This is present in java.util package |
| 3Contains only one method:
public int compareTo(Object obj1) |
3 It contains two methods. |
4 It is marker interface |
4 It is not a marker interface. |