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: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   w ww.j  av a2s  .co  m
}

From source file:Main.java

public static void main(String[] args) {
    Map map = System.getenv();

    Set keys = map.keySet();/*from   w w  w. ja v a  2  s .  com*/
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        String key = (String) iterator.next();
        String value = (String) map.get(key);

        System.out.println(key + " = " + value);
    }
}

From source file:Main.java

public static void main(String[] a) {
    Map<String, String> map = new HashMap<String, String>();
    map.put("key1", "value1");
    map.put("key2", "value2");
    map.put("key3", "value3");
    Set set = map.entrySet();//from  w  w  w  .j a  v a  2s. c o m

    Iterator iter = set.iterator();

    while (iter.hasNext()) {
        Map.Entry entry = (Map.Entry) iter.next();

    }
}

From source file:Main.java

public static void main(String[] a) {
    Map<String, String> map = new HashMap<String, String>();
    map.put("key1", "value1");
    map.put("key2", "value2");
    map.put("key3", "value3");
    Set set = map.entrySet();/*from   w ww.  j  a va  2  s .c  om*/

    Iterator iter = set.iterator();

    while (iter.hasNext()) {
        Map.Entry entry = (Map.Entry) iter.next();
        System.out.println(entry.getKey() + " -- " + entry.getValue());
    }
}

From source file:Main.java

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

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

    Iterator itr = lhashSet.iterator();

    while (itr.hasNext()) {
        System.out.println(itr.next());
    }/*  w  w  w . java2s  .  c o  m*/
}

From source file:Main.java

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

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

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");
    Set set = map.entrySet();/*from w  ww .j  a v  a2s  .c o  m*/

    Iterator iter = set.iterator();

    while (iter.hasNext()) {
        Map.Entry entry = (Map.Entry) iter.next();
        System.out.println(entry.getKey() + " -- " + entry.getValue());
    }
}

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  w  w w.  j  a  v a  2  s. c o m*/

    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) throws Exception {
    int capacity = 10;
    BlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity);

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

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Map weakMap = new WeakHashMap();
    Object keyObject = "";
    Object valueObject = "";
    weakMap.put(keyObject, valueObject);

    Iterator it = weakMap.keySet().iterator();
    while (it.hasNext()) {
        Object key = it.next();//from   ww w . j av a 2  s .c o  m
    }
}