Java Collections

List
  • ArrayList:
  • LinkedList:
Set
  • HashSet
  • LinkedHashSet:
  • SortedSet
  • TreeSet
Map
  • HashMap: HashMap is a  part of java.util package in Java's collection. HashMap is used to store Key & Value pairs, it is denoted as HashMap<K, V>. Its does not guarantees to the order of the map elements i.e. unordered collection. It contains only unique elements i.e doesn’t allow duplicate keys. It is similar to the Hashtable class except that it is unsynchronized. it can have one null key but can have multiple null values. Click here to read in details.
  • LinkedHashMap: It implements the Map interface and extends HashMap class. LinkedHashMap is just like HashMap with an additional feature of maintaining an insertion order of elements inserted into LinkedHashMap.It contains only unique elements. Click here to read in details.
  • SortedMap: SortedMap is an interface in collection framework. Its extends Map interface.The main characteristic of a SortedMap is that, it orders the keys by their natural ordering, or by a specified comparator. Click here to read in details.
  • TreeMap: TreeMap is the implementation of SortedMap interface. it orders the keys by their natural ordering, or by a specified comparator. Click here to read in details.
Q- What is the difference between collection and collections in java?

Collection is an interface,it is the root interface of collection hierarchy.

Collections is class present in java.util.package to define several method for collection object. Collections class has static methods that method returns the collection.

Q- What is the default size & load factor of Collection: ArrayList, Vector, HashSet, Hashtable, and HashMap.

   Collection Java 8 Before Java 8
Initial capacity Load factor Initial capacity Load factor
ArrayList
0 (lazily initialized to 10)
10
Vector
10
10
HashSet
16
0.75
16
0.75
HashMap
16
0.75
16
0.75
Hashtable
16
0.75
11
0.75




Related Tutorials

No comments:

Post a Comment