Skip to main content

Posts

Showing posts with the label Java Collection

Java Collection Interview Questions part- 2

Java Collection 1.What are the major differences between a HashSet and a HashMap? The main difference between a HashSet and a HashMap are: 1.      Base class : A HashSet class implements the Set interface. Whereas a HashMap class implements the Map interface. 2.      Storage : A HashSet is used to store distinct objects. A HashMap is used for storing key & value pairs, so that these can be retrieved by key later on. 3.      Duplicate Elements : A HashSet does not allow storing duplicate elements. A HashMap also does not allow duplicate keys. But we can store duplicate values in a HashMap. 4.      Null Elements : In a HashSet we can store a single null value. In a HashMap we can store single null key, but any number of null values. 5.      Element Type : A HashSet contains only values of objects as its elements. Whereas a HashMap contains entries(key value pairs...