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

public static void main(String args[]) {
    ArrayList<Person> names = new ArrayList<Person>();
    names.add(new Person("E", "T"));
    names.add(new Person("A", "G"));
    names.add(new Person("B", "H"));
    names.add(new Person("C", "J"));

    Iterator iter1 = names.iterator();
    while (iter1.hasNext()) {
        System.out.println(iter1.next());
    }//from   w  w w  .ja  v  a 2s  .  c  o m
    System.out.println("Before sorting");
    Collections.sort(names, new PersonComparator());
    Iterator iter2 = names.iterator();
    while (iter2.hasNext()) {
        System.out.println(iter2.next());
    }
}

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 . jav  a  2 s  .  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:ArraySet.java

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

From source file:Main.java

public static void main(final String[] args) throws Exception {
    Random RND = new Random();
    ExecutorService es = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
    List<Future<String>> results = new ArrayList<>(10);
    for (int i = 0; i < 10; i++) {
        results.add(es.submit(new TimeSliceTask(RND.nextInt(10), TimeUnit.SECONDS)));
    }/*from w w w.  j a v a 2 s  .c om*/
    es.shutdown();
    while (!results.isEmpty()) {
        Iterator<Future<String>> i = results.iterator();
        while (i.hasNext()) {
            Future<String> f = i.next();
            if (f.isDone()) {
                System.out.println(f.get());
                i.remove();
            }
        }
    }
}

From source file:MainClass.java

public static void main(String[] pArgs) throws Exception {
    Date now = new Date();
    System.out.println("now: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(now));
    Iterator iter = DateUtils.iterator(now, DateUtils.RANGE_WEEK_SUNDAY);
    while (iter.hasNext()) {
        Calendar cal = (Calendar) iter.next();
        Date cur = cal.getTime();
        System.out.println("iterate: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(cur));
    }/*from  w  w w .  ja v  a2s  . c  o m*/
}

From source file:InstanceOfDemo.java

/** 
 * Demo method.//from   w  ww. jav  a  2 s .  co m
 *
 * @param args Command Line arguments.
 */
public static void main(final String[] args) {
    final Iterator iter = OBJECT_SET.iterator();
    Object obj = null;

    while (iter.hasNext()) {
        obj = iter.next();
        if (obj instanceof Number) {
            System.out.println(obj);
        }
    }
}

From source file:Main.java

public static void main(String[] args) {
    // create a LinkedList
    LinkedList<String> list = new LinkedList<String>();

    // add some elements
    list.add("Hello");
    list.add("from java2s.com");
    list.add("10");

    // print the list
    System.out.println("LinkedList:" + list);

    // set Iterator as descending
    Iterator x = list.descendingIterator();

    // print list with descending order
    while (x.hasNext()) {
        System.out.println(x.next());
    }/*www. j  a  v  a 2 s . co m*/
}

From source file:de.netallied.functionblock.converter.java2java.util.Directory.java

public static void main(String[] params) {
    File temp = new File("C:\\Temp");
    ArrayList list = Directory.getAll(temp, true);
    Iterator it = list.iterator();
    while (it.hasNext()) {
        System.out.println(((File) (it.next())).getAbsolutePath());
    }//from  w w  w .j a  v  a  2  s  . c  o m
    System.out.println("Number of Files: " + list.size());
}

From source file:MainClass.java

public static void main(String[] args) {
    StopWatch stWatch = new StopWatch();

    //Start StopWatch
    stWatch.start();//from  w w  w  .j  ava 2s.  c  o m

    //Get iterator for all days in a week starting Monday
    Iterator itr = DateUtils.iterator(new Date(), DateUtils.RANGE_WEEK_MONDAY);

    while (itr.hasNext()) {
        Calendar gCal = (Calendar) itr.next();
        System.out.println(gCal.getTime());
    }

    //Stop StopWatch
    stWatch.stop();
    System.out.println("Time Taken >>" + stWatch.getTime());

}

From source file:TreeSetDemo.java

public static void main(String[] argv) {
    //+/*from   w w  w. j  ava 2s .  c o  m*/
    /*
     * A TreeSet keeps objects in sorted order. We use a Comparator
     * published by String for case-insensitive sorting order.
     */
    TreeSet tm = new TreeSet(String.CASE_INSENSITIVE_ORDER);
    tm.add("Gosling");
    tm.add("da Vinci");
    tm.add("van Gogh");
    tm.add("Java To Go");
    tm.add("Vanguard");
    tm.add("Darwin");
    tm.add("Darwin"); // TreeSet is Set, ignores duplicates.

    // Since it is sorted we can ask for various subsets
    System.out.println("Lowest (alphabetically) is " + tm.first());
    // Print how many elements are greater than "k"
    System.out.println(tm.tailSet("k").toArray().length + " elements higher than \"k\"");

    // Print the whole list in sorted order
    System.out.println("Sorted list:");
    java.util.Iterator t = tm.iterator();
    while (t.hasNext())
        System.out.println(t.next());
    //-
}