Java Set iterate via Iterator

Description

Java Set iterate via Iterator


import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class Main {

  public static void main(String[] a) {
    String elements[] = { "CSS", "HTML", "Java", "Javascript", "SQL" };
    Set<String> set = new HashSet<>(Arrays.asList(elements));

    Iterator<String> iter = set.iterator();
    while (iter.hasNext()) {
      System.out.println(iter.next());
    }/*w w  w  .  j  av a2  s. c om*/

  }

}  



PreviousNext

Related