Tag Archives: Collection

Maps in Java

Concrete maps in Java JDK 1.8 Below is the summary of differences between HashMap, LinkedHashMap, TreeMap, and Hashtable in Java: (Source: javarevisited.blogspot.com) If we need to get the key back in insertion order, then use LinkedHashMap. If we need to get the key back in their true/natural order, then use TreeMap. Otherwise, HashMap is best because it… Read More »

Remove duplicated elements from a collection

1. Using LinkedHashSet from a given list Remove duplicated elements by using LinkedHashSet because it contains unique element and in the same order as the List Output in console: 2. Lambda Stream on arbitrary key Output in console:

Java Collection with Comparators and Comparables

1. Try TreeSet with Comparator and Comparable In Java, TreeSet is a member of the Java Collection Framework. Elements of the TreeSet are ordered by using their natural ordering, or by a Comparator. A Big-O notation of tree but not specific to Java refers to a pretty good website: bigocheatsheet.com Java supports two interfaces to… Read More »