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:DynaBeansExampleV3.java

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

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

    RowSetDynaClass rsdc = new RowSetDynaClass(rs);

    conn.close();

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

}

From source file:MainClass.java

public static void main(String args[]) {
    Set simpsons = new HashSet();
    simpsons.add("B");
    simpsons.add("H");
    simpsons.add("L");
    simpsons = Collections.synchronizedSet(simpsons);
    synchronized (simpsons) {
        Iterator iter = simpsons.iterator();
        while (iter.hasNext()) {
            System.out.println(iter.next());
        }//from   www . j a v  a  2  s.  c o m
    }
    Map map = Collections.synchronizedMap(new HashMap(89));
    Set set = map.entrySet();
    synchronized (map) {
        Iterator iter = set.iterator();
        while (iter.hasNext()) {
            System.out.println(iter.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  2 s . com
    treeadd.add(2);
    treeadd.add(3);
    treeadd.add(4);
    treeadd.add(5);
    treeadd.add(6);
    treeadd.add(7);
    treeadd.add(8);

    TreeSet<Integer> treetailsetincl = (TreeSet<Integer>) treeadd.tailSet(5, true);

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

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

From source file:ArrayListGenericDemo.java

public static void main(String[] args) {
    ArrayList<String> data = new ArrayList<String>();
    data.add("hello");
    data.add("goodbye");

    // data.add(new Date()); This won't compile!

    Iterator<String> it = data.iterator();
    while (it.hasNext()) {
        String s = it.next();//from   www. j  a  va2  s  .  c o m
        System.out.println(s);
    }
}

From source file:MyComparator.java

public static void main(String[] args) {
    TreeMap tm = new TreeMap();
    tm.put(1, new Double(344.34));
    tm.put(0, new Double(123.22));
    tm.put(4, new Double(138.00));
    tm.put(2, new Double(919.22));
    tm.put(3, new Double(-119.08));

    List<Map.Entry> valueList = new ArrayList(tm.entrySet());
    Collections.sort(valueList, new MyComparator());

    Iterator<Map.Entry> iterator = valueList.iterator();
    while (iterator.hasNext()) {
        Map.Entry entry = iterator.next();
        System.out.println("Value: " + entry.getValue());
    }/*w ww  .  j  av a 2 s. c  o  m*/
}

From source file:Main.java

public static void main(String[] args) {
    Date d1 = new Date();
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, 22);//ww  w.  j  a  v  a2  s .c  o  m
    Date d2 = cal.getTime();

    Iterator<Date> i = new DateIterator(d1, d2);
    while (i.hasNext()) {
        Date date = i.next();
        System.out.println(date);
    }
}

From source file:MainClass.java

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

    String str;//www. ja va2s  .c  om
    double bal;

    balance.put("A", 4.34);
    balance.put("B", 3.22);
    balance.put("C", 8.00);
    balance.put("D", 9.22);
    balance.put("E", -9.08);

    Set<String> set = balance.keySet();

    Iterator<String> itr = set.iterator();
    while (itr.hasNext()) {
        str = itr.next();
        System.out.println(str + ": " + balance.get(str));
    }

    System.out.println();

    bal = balance.get("A");
    balance.put("A", bal + 1000);
    System.out.println("A's new balance: " + balance.get("A"));
}

From source file:Main.java

public static final void main(String[] args) {
    Map<String, String> m = new HashMap<>();
    m.put("a", "alpha");
    m.put("b", "beta");

    Iterator<Map.Entry<String, String>> it = m.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, String> entry = it.next();
        if (entry.getKey() == "b") {
            entry.setValue("new Value");
        }/*from  w w  w . j a v a 2s . c  om*/
    }
    it = m.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, String> entry = it.next();
        System.out.println("key = " + entry.getKey() + ", value = " + entry.getValue());
    }
}

From source file:IteratorDemo.java

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

    al.add("C");/* w  ww . j  a  va  2  s . com*/
    al.add("A");
    al.add("E");
    al.add("B");
    al.add("D");
    al.add("F");

    Iterator<String> itr = al.iterator();
    while (itr.hasNext()) {
        String element = itr.next();
        System.out.print(element + " ");
    }

    ListIterator<String> litr = al.listIterator();
    while (litr.hasNext()) {
        String element = litr.next();
        litr.set(element + "+");
    }

    itr = al.iterator();
    while (itr.hasNext()) {
        String element = itr.next();
        System.out.print(element + " ");
    }

    while (litr.hasPrevious()) {
        String element = litr.previous();
        System.out.print(element + " ");
    }
}

From source file:de.rwhq.btree.run.PrintTree.java

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

    final File f = new File("/tmp/indexha");
    if (!f.exists())
        throw new IllegalArgumentException("File does not exist");

    final ResourceManager resourceManager = new ResourceManagerBuilder().file(f).build();
    final BTree<Integer, String> tree = BTree.create(resourceManager, IntegerSerializer.INSTANCE,
            FixedStringSerializer.INSTANCE_1000, IntegerComparator.INSTANCE);

    final Iterator<String> it = tree.getIterator();
    while (it.hasNext()) {
        System.out.println(it.next());
    }//  w  w  w  .  j  a v a  2 s . co  m
}