Sunday, June 3, 2018

LinkedHashSet Class in Java with Example

LinkedHashSet Class:- Earlier we have discussed HashSet class. In this tutorial we will learn about LinkedHashSet class.

- It is a class which extends HashSet class and implements Set interface.
- Maintains insertion order.
- Contains unique elements

LinkedHashSet-Java-Collection




Syntax:

LinkedHashSet <String> hs = new LinkedHashSet <String>();


Sample Program of LinkedHashSet: 

import java.util.LinkedHashSet;

public class LinkedHashSetDemo {
     
      public static void main(String[] args) {
           
            LinkedHashSet <String> hs = new LinkedHashSet <String>();
           
            hs.add("John");
            hs.add("Miller");
            hs.add("Denis");
            hs.add("Javed");
            hs.add("John");
           
            System.out.println("Elements of LinkedHashSet class:" + hs);
      }


}

OutPut: 

Elements of LinkedHashSet class:[John, Miller, Denis, Javed]




                                              
                     HashSet Class in Java with Example
                           Collection in Java





No comments:

Post a Comment