1 / 4

LinkedHashSet in Java - Quipoin

LinkedHashSet in Java - Quipoin<br>LinkedHashSet is the subclass of the HashSet class.It is implemented by using the hybrid data structure LinkedList and HashTable.It maintains the order of insertion.The default capacity of LinkedHashMap is 16 and it grows based on the load factor or fill ratio i.e. 0.75.The main difference between HashSet and LinkedhashSet is that HashSet doesn't maintain the insertion order of insertion, and LinkedHashset maintains the order. Let's see one example of how the Linkedhashset works.<br>for more free learning visit us at:<br>https://quipoin.com/view/Java/LinkedHashSet

quipoin
Download Presentation

LinkedHashSet in Java - Quipoin

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. LinkedHashSet LinkedHashSetin Java

  2. Overview • LinkedHashSet is the subclass of the HashSet class. • It is implemented by using the hybrid data structure LinkedList and HashTable. • It maintains the order of insertion. • The default capacity of LinkedHashMap is 16 and it grows based on the load factor or fill ratio i.e. 0.75 • The Hashtable structure is used for the unique storage of elements whereas LinkedList is used to preserve the insertion order. • The main difference between HashSet and LinkedhashSet is that HashSet doesn't maintain the insertion order of insertion, and LinkedHashset maintains the order. Let's see one example of how the Linkedhashset works.

  3. Program import java.util.Iterator; import java.util.LinkedHashSet; public class Employee { public static void main(String[] args) { LinkedHashSet<String> lh=new LinkedHashSet<>(); lh.add("Vivek"); lh.add("Atul"); lh.add("Prince"); lh.add("Prashant"); lh.add("Naveen"); Iterator<String> itr=lh.iterator(); while (itr.hasNext()) { String str = (String) itr.next(); System.out.println(str); } } }

  4. Output: Vivek Atul Prince Prashant Naveen • We can observe the result is in order of insertion.

More Related