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[] args) {
    Map charsets = Charset.availableCharsets();
    Iterator iterator = charsets.values().iterator();
    while (iterator.hasNext()) {
        Charset cs = (Charset) iterator.next();
        System.out.print(cs.displayName());
        if (cs.isRegistered()) {
            System.out.print(" (registered): ");
        } else {//w ww . ja  va2 s  .  c o m
            System.out.print(" (unregistered): ");
        }
        System.out.print(cs.name());
        Iterator names = cs.aliases().iterator();
        while (names.hasNext()) {
            System.out.print(", ");
            System.out.print(names.next());
        }
        System.out.println();
    }
}

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) {
    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  ww  w. j a  va  2s .co m*/
    }
}

From source file:Main.java

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

    treeadd.add(1);/*ww  w. ja  v  a2  s.c om*/
    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:IteratorDemo.java

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

    al.add("C");//from  w  ww  .  ja v  a2  s.  c o m
    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());
    }//  ww w  .  j a va2  s.c  o  m
}

From source file:DynaBeansExampleV3.java

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

    Connection conn = getConnection();
    PreparedStatement ps = conn/*w  w  w .ja  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: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());
    }/*from  w w w  .j a  va  2 s.  com*/
}

From source file:MainClass.java

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

    al.add("C");//from www  .  j  a  va2  s.co m
    al.add("A");
    al.add("E");
    al.add("B");
    al.add("D");
    al.add("F");

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

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

    // Now, display the list backwards.
    System.out.print("Modified list backwards: ");
    while (litr.hasPrevious()) {
        String element = litr.previous();
        System.out.print(element + " ");
    }
}

From source file:Main.java

public static void main(String[] args) {
    List<Integer> _numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    Iterator<Integer> iter = _numbers.stream().filter(value -> value % 2 == 0).iterator();

    while (iter.hasNext()) {
        System.out.println(iter.next());
    }/* www . ja  v  a  2 s.  c  o  m*/
}