- LinkedHashSet is Hashtable & 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 remove method.
- Given a LinkedHashSet collection of String objects in java.
- Set<String> cmputerGenerations = new LinkedHashSet<>();
- Convert LinkedHashSet of String object to ArrayList collection in java (with example)
1. Convert LinkedHashSet of String objects to ArrayList collection 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( "1. LinkedHashSet: " + cmputerGenerations); ArrayList<String>linkedHashSetToArrayList = new ArrayList<>(cmputerGenerations); System.out.println( "2. ArrayList:" + linkedHashSetToArrayList); } } |
2. Convert LinkedHashSet of String objects to ArrayList collection (example)
1. LinkedHashSet: [VacuumTubes, Transistors, IntegratedCircuits, Microprocessors, ArtificialIntelligence] 2. ArrayList:[VacuumTubes, Transistors, IntegratedCircuits, Microprocessors, ArtificialIntelligence] |