Example usage for java.util Iterator hasNext

List of usage examples for java.util Iterator hasNext

Introduction

In this page you can find the example usage for java.util Iterator hasNext.

Prototype

boolean hasNext();

Source Link

Document

Returns true if the iteration has more elements.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    SortedSet<String> set = new TreeSet<String>();
    set.add("b");
    set.add("c");
    set.add("a");

    Iterator it = set.iterator();
    while (it.hasNext()) {
        Object element = it.next();
    }/*from   ww  w  . ja  va2 s  . c  o m*/
    String[] array = (String[]) set.toArray(new String[set.size()]);
}

From source file:MainClass.java

public static void main(String[] args) {
    List list = Arrays.asList("A", "B", "C", "D");
    Iterator iterator = list.iterator();
    while (iterator.hasNext()) {
        String element = (String) iterator.next();
        System.out.println(element);
    }//  w  ww.j a v a  2 s . c o  m

}

From source file:MainClass.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    Set set = new HashSet(Arrays.asList(elements));

    Iterator iter = set.iterator();
    while (iter.hasNext()) {
        System.out.println(iter.next());
    }/* w  ww.  j a  v a  2 s .c  o m*/

}

From source file:Main.java

public static void main(String[] args) {
    String[] array = { "A", "B", "C", "D" };
    List list = Arrays.asList(array);

    Iterator iterator = list.iterator();
    while (iterator.hasNext()) {
        System.out.println((String) iterator.next());
    }/*from  ww w  .  j a v a 2  s  . co m*/
}

From source file:Main.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    HashSet<String> set = new HashSet<String>(Arrays.asList(elements));

    Iterator iter = set.iterator();
    while (iter.hasNext()) {
        System.out.println(iter.next());
    }/*from  w ww. jav  a2s.co  m*/

}

From source file:Main.java

public static void main(String[] args) {
    TreeMap<String, String> treeMap = new TreeMap<String, String>();
    treeMap.put("1", "One");
    treeMap.put("2", "Two");
    treeMap.put("3", "Three");

    Collection c = treeMap.values();
    Iterator itr = c.iterator();

    while (itr.hasNext()) {
        System.out.println(itr.next());
    }// w w w.  ja  va2 s.c  o  m
}

From source file:MainClass.java

public static void main(String[] a) {
    ArrayList<String> nums = new ArrayList<String>();
    nums.add("O");
    nums.add("Two");
    nums.add("Three");
    nums.add("Four");

    String s;//from  www .jav  a 2  s.  c o m
    Iterator e = nums.iterator();
    while (e.hasNext()) {
        s = (String) e.next();
        System.out.println(s);
    }
}

From source file:MainClass.java

public static void main(String[] s) {
    Hashtable table = new Hashtable();
    table.put("key1", "value1");
    table.put("key2", "value2");
    table.put("key3", "value3");

    Set set = table.entrySet();//w ww.  java2  s.co  m
    Iterator it = set.iterator();
    while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        System.out.println(entry.getKey() + " : " + entry.getValue());
    }
}

From source file:Main.java

public static void main(String[] args) {
    LinkedList<String> lList = new LinkedList<String>();
    lList.add("1");
    lList.add("2");
    lList.add("3");
    lList.add("4");
    lList.add("5");

    Iterator itr = lList.iterator();
    while (itr.hasNext()) {
        System.out.println(itr.next());
    }// ww w .  j  a  v  a  2s .  com
}

From source file:Main.java

public static void main(String[] args) {
    TreeSet<Integer> tSet = new TreeSet<Integer>();

    tSet.add(new Integer("1"));
    tSet.add(new Integer("2"));
    tSet.add(new Integer("3"));

    Iterator itr = tSet.iterator();

    while (itr.hasNext()) {
        System.out.println(itr.next());
    }//  w w  w.  jav a  2 s .c  o m
}