examples of linked hash set in java programming

0

Linked Hash set:

  • An ordered version of the hash set is known as Linked Hash Set.
  • Maintains a doubly-Linked list of all the elements.
  • Use this when an iteration order is required.

Example:

public class Fruit {
public static void main (String[ ] args){
LinkedHashSet<String>; names = new LinkedHashSet <String>( ) ;
 names.add(“banana”);
 names.add(“cherry”);
 names.add(“apple”);
 names.add(“kiwi”);
 names.add(“banana”);
 System.out.println (names);
 }
}

Output:

[banana, cherry, apple, kiwi]

It maintains the insertion order in which they have been added to the Set. Duplicates are not allowed.

All Contributions

total contributions (0)

New to examplegeek.com?

Join us