Example usage for java.util Iterator next

List of usage examples for java.util Iterator next

Introduction

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

Prototype

E next();

Source Link

Document

Returns the next element in the iteration.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int capacity = 10;
    BlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity);

    for (int i = 0; i < 10; i++) {
        queue.add(i);//from   w  ww .j a  v a2 s.  c  o m
    }
    Iterator<Integer> it = queue.iterator();
    while (it.hasNext()) {
        System.out.println(it.next());
    }
}

From source file:OldStyle.java

public static void main(String args[]) {
    ArrayList list = new ArrayList();

    list.add("one");
    list.add("two");
    list.add("three");
    list.add("four");

    Iterator itr = list.iterator();
    while (itr.hasNext()) {
        String str = (String) itr.next(); // explicit cast needed here.

        System.out.println(str + " is " + str.length() + " chars long.");
    }//from   www  .  j  av a 2s .  c om
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int capacity = 10;
    ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity);

    for (int i = 0; i < 10; i++) {
        queue.add(i);/*from   w  w w  .j  av a 2  s .  c  om*/
    }
    Iterator<Integer> it = queue.iterator();
    while (it.hasNext()) {
        System.out.println(it.next());
    }
}

From source file:Main.java

public static void main(String[] args) {
    HashMap<String, String> hMap = new HashMap<String, String>();

    hMap.put("1", "One");
    hMap.put("2", "Two");
    hMap.put("3", "Three");

    Set st = hMap.keySet();//w  ww .j  a  v a2 s . c  o m
    Iterator itr = st.iterator();

    while (itr.hasNext())
        System.out.println(itr.next());

    // remove 2 from Set
    st.remove("2");

    System.out.println(hMap.containsKey("2"));
}

From source file:MainClass.java

public static void main(String[] a) {
    Map map = new HashMap();
    map.put("key1", "value1");
    map.put("key2", "value2");
    map.put("key3", "value3");
    map.put(null, null);/*from   ww w . ja  va2s  .com*/

    Set set = map.keySet();

    Iterator iter = set.iterator();

    while (iter.hasNext()) {
        System.out.println(iter.next());
    }
}

From source file:Main.java

public static void main(String[] argv) {
    Map map = new HashMap();

    map.put("Adobe", "Mountain View, CA");
    map.put("IBM", "White Plains, NY");
    map.put("Learning Tree", "Los Angeles, CA");

    Iterator k = map.keySet().iterator();
    while (k.hasNext()) {
        String key = (String) k.next();
        System.out.println("Key " + key + "; Value " + (String) map.get(key));
    }/*from  w  w w .  java  2  s  . com*/
}

From source file:Main.java

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

    vec.add(4);/*from   w w w .j a  va  2  s.  co m*/
    vec.add(3);
    vec.add(2);
    vec.add(1);

    System.out.println(vec);

    Iterator<Integer> it = vec.iterator();
    while (it.hasNext()) {
        System.out.println(it.next());
    }
}

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);
    }/*from   w  w  w . ja v  a  2 s .  c om*/

}

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  w  w.ja  v a 2s  .c o  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[] argv) {
    // Create the sorted set
    Set<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();
        System.out.println(element);
    }/*from  w w w.  ja  v  a 2  s  . com*/

    // Create an array containing the elements in a set
    String[] array = (String[]) set.toArray(new String[set.size()]);
    Arrays.toString(array);
}