iterate through hash_set c++ code example
Example 1: loop through set c++
#include <iostream>
#include <set>
int main ()
{
int myints[] = {75,23,65,42,13};
std::set<int> myset (myints,myints+5);
std::cout << "myset contains:";
for (std::set<int>::iterator it=myset.begin(); it!=myset.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}
Example 2: HashSet iterator() method in java
import java.util.HashSet;
import java.util.Iterator;
public class HashSetIteratorMethodExample
{
public static void main(String[] args)
{
HashSet<String> hs = new HashSet<String>();
hs.add("Welcome");
hs.add("hello");
hs.add("world");
hs.add("core");
hs.add("java");
System.out.println("HashSet values are: " + hs);
Iterator<String> value = hs.iterator();
System.out.println("iterator values are: ");
while(value.hasNext())
{
System.out.println(value.next());
}
}
}