Tutorialspoint

Iterate through elements of Java LinkedHashSet

import java.util.*;
public class Demo {
   public static void main(String[] args) {
		LinkedHashSet<Integer> set = new LinkedHashSet<Integer>();
		set.add(10);
		set.add(20);
		set.add(30);
		set.add(40);
		set.add(50);
		set.add(60);
		System.out.println("LinkedHashSet...");
		System.out.println(set);
		System.out.println("Iterating...");
		Iterator i = set.iterator();
		while (i.hasNext()){
		   System.out.println(i.next());
      }
   }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.