Category Archives: LinkedHashSet

Convert LinkedHashSet collection of String objects to Array in java (example)

Hashtable and linked list implementation of the Set interface, with predictable iteration order. LinkedHashSet maintains the Insertion order of elements using LinkedList LinkedHashSet is UnSynchronized and not thread safe. Given a LinkedHashSet containing String objects in java. Set<String> computerGenerations = new LinkedHashSet<>() We would like to convert LinkedHashSet to Array of Strings in java. We… Read More »

Convert LinkedHashSet to ArrayList in java (example)

Given a LinkedHashSet containing String objects. Convert LinkedHashSet to ArrayList of strings. Set<String> cmputerGenerations = new LinkedHashSet<>(); Program – Convert LinkedHashSet to ArrayList in java package org.learn.collection.set.lhset; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.Set; public class DemoLinkedHashSetToArrayList { public static void main(String[] args) { Set<String> cmputerGenerations = new LinkedHashSet<>(); cmputerGenerations.add(“VacuumTubes”); cmputerGenerations.add(“Transistors”); cmputerGenerations.add(“IntegratedCircuits”); cmputerGenerations.add(“Microprocessors”); cmputerGenerations.add(“ArtificialIntelligence”); System.out.println(“Set: “+… Read More »

Iterate or loop LinkedHashSet collection of String objects in java8 (with example)

Hashtable and linked list implementation of the Set interface, with predictable iteration order. LinkedHashSet maintains the Insertion order of elements using LinkedList LinkedHashSet is UnSynchronized and not thread safe. Iterator of LinkedHashSet is fail-fast. Iterator will throw ConcurrentModificationException, if LinkedHashSet modified at any time after the iterator is created, in any way except through the iterator’s own… Read More »

Convert LinkedHashSet to TreeSet in java (example)

Given a LinkedHashSet containing Computer’s generation (String). Set<String> cmputerGenerations = new LinkedHashSet<>(); Convert LinkedHashSet to TreeSet. String objects will be sorted using TreeSet class. Program – Convert LinkedHashSet to TreeSet in java package org.learn.collection.set.lhset; import java.util.LinkedHashSet; import java.util.Set; import java.util.TreeSet; public class DemoLinkedHashSetToTreeSet { public static void main(String[] args) { Set<String> cmputerGenerations = new LinkedHashSet<>(); cmputerGenerations.add(“VacuumTubes”);… Read More »

What is LinkedHashSet collection in java (class hierarchy & example)

Hashtable and linked list implementation of the Set interface, with predictable iteration order. LinkedHashSet maintains the Insertion order of elements using LinkedList LinkedHashSet is UnSynchronized and not thread safe. Iterator of LinkedHashSet is fail-fast. Iterator will throw ConcurrentModificationException, if LinkedHashSet modified at any time after the iterator is created, in any way except through the iterator’s own… Read More »