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[] args) {
    Map<String, Charset> charsets = Charset.availableCharsets();
    Iterator<Charset> iterator = charsets.values().iterator();
    while (iterator.hasNext()) {
        Charset cs = (Charset) iterator.next();
        System.out.println(cs.displayName());
        System.out.println(cs.canEncode());
    }/* www .j a  v  a2  s. c o m*/
}

From source file:Main.java

public static void main(String[] args) {

    TreeSet<Integer> treeadd = new TreeSet<Integer>();

    treeadd.add(1);/*from   w ww.  j a  va 2 s .  c  om*/
    treeadd.add(13);
    treeadd.add(17);
    treeadd.add(22);

    Iterator<Integer> iterator = treeadd.iterator();

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

From source file:Main.java

public static void main(String[] args) {

    TreeSet<Integer> treeadd = new TreeSet<Integer>();

    treeadd.add(12);/*from   w  w  w .  ja  va2 s. c  o  m*/
    treeadd.add(13);
    treeadd.add(14);
    treeadd.add(15);

    Iterator<Integer> iterator = treeadd.iterator();

    while (iterator.hasNext()) {
        System.out.print(iterator.next());
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    Map charSets = Charset.availableCharsets();
    Iterator it = charSets.keySet().iterator();
    while (it.hasNext()) {
        String csName = (String) it.next();
        System.out.print(csName);
        Iterator aliases = ((Charset) charSets.get(csName)).aliases().iterator();
        if (aliases.hasNext())
            System.out.print(": ");
        while (aliases.hasNext()) {
            System.out.print(aliases.next());
            if (aliases.hasNext())
                System.out.print(", ");
        }/*w w  w. java2 s .  co m*/
        System.out.println();
    }
}

From source file:Main.java

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

    arrlist.add(1);/*from   w ww . j  a v  a2  s  .  c  om*/
    arrlist.add(2);
    arrlist.add(3);
    arrlist.add(4);
    arrlist.add(5);

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

}

From source file:Main.java

public static void main(String[] args) {
    Map errors = new HashMap();

    errors.put("404", "A.");
    errors.put("403", "B.");
    errors.put("500", "C.");

    String errorDesc = (String) errors.get("404");
    System.out.println("Error 404: " + errorDesc);

    Iterator iterator = errors.keySet().iterator();
    while (iterator.hasNext()) {
        String key = (String) iterator.next();
        System.out.println("Error " + key + " means " + errors.get(key));
    }/*from   w ww.ja v a 2s .c  o  m*/
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String url = "http://www.java2s.com";
    Document doc = Jsoup.connect(url).userAgent(
            "Mozilla/5.0 (Windows; U; WindowsNT 5.1;" + " en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
            .get();/*w  w  w.  j a  va2 s.c o m*/

    Elements resultDivElems = doc.select("div");
    Iterator<Element> itr = resultDivElems.iterator();

    while (itr.hasNext()) {
        System.out.println(((Element) itr.next()).text());
    }
}

From source file:Main.java

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

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

    Set st = ht.keySet();//from  w  w  w  .j  ava2s.c  o m

    Iterator itr = st.iterator();

    while (itr.hasNext()) {
        System.out.println(itr.next());
    }
    st.remove("2");

    Enumeration e = ht.keys();
    while (e.hasMoreElements()) {
        System.out.println(e.nextElement());
    }
}

From source file:OldStyle.java

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

    // These lines store strings, but any type of object 
    // can be stored.  In old-style code, there is no  
    // convenient way restrict the type of objects stored 
    // in a collection 
    list.add("one");
    list.add("two");
    list.add("three");
    list.add("four");

    Iterator itr = list.iterator();
    while (itr.hasNext()) {

        // To retrieve an element, an explicit type cast is needed 
        // because the collection stores only Object. 
        String str = (String) itr.next(); // explicit cast needed here. 

        System.out.println(str + " is " + str.length() + " chars long.");
    }/*from   w ww.jav  a  2s.co m*/
}

From source file:Main.java

public static void main(String[] args) {
    List<String> syncList = Collections.synchronizedList(new ArrayList<String>());

    syncList.add("one");
    syncList.add("two");
    syncList.add("three");

    synchronized (syncList) {
        Iterator<String> iterator = syncList.iterator();
        while (iterator.hasNext()) {
            System.out.println("item: " + iterator.next());
        }//from  w  ww . j  av a2 s  .  c om
    }
}