Java List get elements with Iterator

Description

Java List get elements with Iterator

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

public class Main {
  public static void main(String[] a) {

    List<String> list = Arrays.asList(new String[] { "HTML", "C++", "Java", "Java" });
    Iterator<String> iter = list.iterator();

    while (iter.hasNext()) {
      System.out.println(iter.next());
    }//w ww.  ja va  2s.  c o  m

  }
}



PreviousNext

Related