loop through set code example

Example 1: loop through set python

#Create a set 
num_set = set([0, 1, 2, 3, 4, 5])
for n in num_set:
  print(n)

Example 2: set iteration java

import java.util.HashSet;
import java.util.Set;

class IterateHashSet{ 
  public static void main(String[] args) {
     Set<String> hset = new HashSet<String>();
     hset.add("Chaitanya");
     hset.add("Rahul");
 
     for (String temp : hset) {
        System.out.println(temp);
     }
  }
}

Example 3: set iteration java

import java.util.HashSet;
import java.util.Iterator;

class IterateHashSet{ 
  public static void main(String[] args) {
     HashSet<String> hset = new HashSet<String>();
     hset.add("Chaitanya");
     hset.add("Rahul");
 
     Iterator<String> it = hset.iterator();
     while(it.hasNext()){
        System.out.println(it.next());
     }
  }
}