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) {

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

    treeadd.add(1);/*from w w w  . j  a  v a 2  s .co  m*/
    treeadd.add(3);
    treeadd.add(17);
    treeadd.add(2);

    System.out.println("Last element is: " + treeadd.pollLast());

    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(1);//from   w  ww .  j a  v a 2s .  c o m
    treeadd.add(3);
    treeadd.add(17);
    treeadd.add(2);

    System.out.println("First element is: " + treeadd.pollFirst());

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

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

From source file:DynaBeansExampleV2.java

public static void main(String args[]) throws Exception {

    Connection conn = getConnection();
    PreparedStatement ps = conn//ww  w  .  j a  va  2 s.c  om
            .prepareStatement("SELECT * from movie, person " + "WHERE movie.director = person.Id");
    ResultSet rs = ps.executeQuery();

    ResultSetDynaClass rsdc = new ResultSetDynaClass(rs);

    Iterator itr = rsdc.iterator();
    while (itr.hasNext()) {
        DynaBean bean = (DynaBean) itr.next();
        System.err.println(bean.get("title"));
    }

    conn.close();
}

From source file:Main.java

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

    tree.add(12);/* w  w  w. j  a v a  2  s  . c om*/
    tree.add(13);
    tree.add(14);

    // cloning tree into clinetree
    TreeSet<Integer> clonetree = (TreeSet) tree.clone();

    // creating iterator
    Iterator<Integer> iterator = clonetree.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 ww. j ava  2 s .  c o  m*/
    treeadd.add(13);
    treeadd.add(14);
    treeadd.add(15);

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

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

    treeadd.clear();
    System.out.println(treeadd.size());
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    Hashtable hash = new Hashtable(89);
    hash.put("one", "two");
    hash.put("two", "three");
    hash.put("three", "four");
    hash.put("four", "five");
    System.out.println(hash);// w ww  .  j  a  va 2 s  .com
    System.out.println(hash.size());
    Enumeration e = hash.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        System.out.println(key + " : " + hash.get(key));
    }
    Set set = hash.entrySet();
    Iterator it = set.iterator();
    while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        System.out.println(entry.getKey() + " : " + entry.getValue());
    }
}

From source file:EnumerationIterator1.java

public static void main(String args[]) {
    String elements[] = { "Java", "Source", "and", "Support", "." };
    Vector v = new Vector(Arrays.asList(elements));
    Enumeration e = v.elements();
    Iterator itor = EnumerationIterator1.iterator(e);
    while (itor.hasNext()) {
        System.out.println(itor.next());
    }//w  w  w . j a v a  2s  .c o  m
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Preferences prefs = Preferences.userNodeForPackage(MainClass.class);
    prefs.put("key1", "value1");
    prefs.put("key2", "value2");
    prefs.putInt("intValue", 4);
    prefs.putBoolean("booleanValue", true);
    int usageCount = prefs.getInt("intValue", 0);
    usageCount++;//from  w w w.  jav  a2s  .c o  m
    prefs.putInt("UsageCount", usageCount);
    Iterator it = Arrays.asList(prefs.keys()).iterator();
    while (it.hasNext()) {
        String key = it.next().toString();
        System.out.println(key + ": " + prefs.get(key, null));
    }
    System.out.println(prefs.getInt("booleanValue", 0));
}

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());
        if (cs.isRegistered()) {
            System.out.print(" (registered): ");
        } else {//w ww  . j a  v a  2 s.c  o  m
            System.out.print(" (unregistered): ");
        }
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Preferences prefs = Preferences.userNodeForPackage(Main.class);
    prefs.put("key1", "value1");
    prefs.put("key2", "value2");
    prefs.putInt("intValue", 4);
    prefs.putBoolean("booleanValue", true);
    int usageCount = prefs.getInt("intValue", 0);
    usageCount++;/*from w  w  w.ja va2 s.co m*/
    prefs.putInt("UsageCount", usageCount);
    Iterator it = Arrays.asList(prefs.keys()).iterator();
    while (it.hasNext()) {
        String key = it.next().toString();
        System.out.println(key + ": " + prefs.get(key, null));
    }
    System.out.println(prefs.getInt("booleanValue", 0));
}