How to use the LinkedHashSet?

How to use the LinkedHashSet?

Previous Home Next

 

This Example will show how to use the LinkedHashSet in java language. and how to add the elements and retrieve elements .

This Example shows us  how to add elements using add(object obj) to populated the LinkedHashSet.and how to retrieve the elements from the LinkedHashSet.
 Two methods are used in this Program one is add(object obj) method to populated the LinkedHashSet .and other is get method to display the elements of the LinkedHashSet. 

First makes the object of the LinkedHashSet.i.e. Lhst. and through this Lhst add the elements to the LinkedHashSet.and then call the object in println to display the elements of the Set.

 

/**
*
*/
package Example;
import java.util.LinkedHashSet;
import java .util.Iterator;

/**
* @author R4R
*
*/
public class IterateElements {





/**
* @param args
*/
public static void main(String[] args) {
LinkedHashSet Lhst = new LinkedHashSet();
Lhst.add("10");
Lhst.add("11");
Lhst.add("12");
Lhst.add("13");
Lhst.add("14");
Lhst.add("15");
Lhst.add("16");



System.out.println(" The elements of LinkedHashSet are:"+Lhst);


// TODO Auto-generated method stub


}

}

 The LinkedHashSet contains the elements :[10, 11, 12, 13, 14, 15, 16]

Previous Home Next