java tutorial - Java TreeMap example - java programming - learn java - java basics - java for beginners
Learn java - java tutorial - Simple Java TreeMap - java examples - java programs
Java TreeMap example:
- TreeMap is Red-Black tree based NavigableMap implementation. It is sorted according to the natural ordering of its keys.
- The TreeMap class implements Map interface same to HashMap class. The main difference between them is HashMap is an unordered collection while TreeMap is sorted in the ascending order of its keys. It is unsynchronized collection class that means it is not appropriate for thread-safe operations until unless synchronized clearly.
Learn java - java tutorial - Simple Java TreeMap - java examples - java programs
- Java HashSet class is used to create a collection which uses a hash table for storage. It inherits the AbstractSet class as well as implements Set interface.
- The main points concerning Java HashSet class are:
- HashSet stores the elements by using a mechanism named hashing.
- HashSet contains unique elements only.
Difference between List and Set :
- List can contain duplicate elements whereas Set contains unique elements only.
Hierarchy of HashSet class:
- The HashSet class extends AbstractSet class which implements Set interface. The Set interface inherits Collection and Iterable interfaces in hierarchical order.
HashSet class declaration :
- Let's see the declaration for java.util.HashSet class.
- public class HashSet<E> extends AbstractSet<E>implements Set<E>, Cloneable, Serializable