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 List toList(Set set) {
    if (set == null) {
        return null;
    }/*from ww w  .ja v a2s. co m*/
    if (set.size() == 0)
        return new ArrayList();
    List list = new ArrayList();
    Iterator itor = set.iterator();
    while (itor.hasNext()) {
        Object obj = itor.next();
        list.add(obj);
    }
    return list;
}

From source file:Main.java

public static final <E, F extends Collection<E>> F removeNulls(F collection) {
    Iterator<E> iterator = collection.iterator();
    while (iterator.hasNext()) {
        if (iterator.next() == null) {
            iterator.remove();/*from   w ww .  ja  va2  s .  co m*/
        }
    }

    return collection;
}

From source file:Main.java

/**
 * Compares two collections returning the number of elements they have in common
 * /* www. ja  v a  2  s .  c om*/
 * @param <T>
 * @param one
 * @param two
 * @return
 */
public static <T> int collectionCompare(Collection<T> one, Collection<T> two) {
    int count = 0;

    Iterator<T> e = one.iterator();
    while (e.hasNext()) {
        if (two.contains(e.next()))
            ++count;
    }

    return count;
}

From source file:Main.java

public static <E> boolean isEmpty(Collection<E> collection) {
    if (collection == null || collection.isEmpty()) {
        return true;
    }/*from w  ww. j  a  v  a 2 s  .  c om*/
    Iterator<E> it = collection.iterator();
    while (it.hasNext()) {
        E type = (E) it.next();
        if (type != null) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

public static Map<String, String> parseStringJsonMap(JSONObject object) throws JSONException {
    Map<String, String> map = new ArrayMap<String, String>();
    Iterator<String> keys = object.keys();
    while (keys.hasNext()) {
        String key = keys.next();
        map.put(key, object.getString(key));
    }/*  w  w w.  j a  va  2  s .c o  m*/
    return map;
}

From source file:Main.java

public static Map<String, Integer> parseIntegerJsonMap(JSONObject object) throws JSONException {
    Map<String, Integer> map = new ArrayMap<String, Integer>();
    Iterator<String> keys = object.keys();
    while (keys.hasNext()) {
        String key = keys.next();
        map.put(key, object.getInt(key));
    }//from  www .j a v  a2 s  .  c o m
    return map;
}

From source file:Main.java

public static Map<String, Long> parseLongJsonMap(JSONObject object) throws JSONException {
    Map<String, Long> map = new ArrayMap<String, Long>();
    Iterator<String> keys = object.keys();
    while (keys.hasNext()) {
        String key = keys.next();
        map.put(key, object.getLong(key));
    }/* ww w  . j  ava2 s .  c  o  m*/
    return map;
}

From source file:Main.java

private static <T> void display(final Iterator<T> iterator) {
    while (iterator.hasNext()) {
        final T item;
        item = iterator.next();
        System.out.println(item);
    }//  w  ww  .  j a v  a  2 s. c om
}

From source file:Main.java

public static void display(Collection collection) {
    Iterator iterator = collection.iterator();
    while (iterator.hasNext()) {
        System.out.print(iterator.next() + " ");
    }// ww w. ja  v a  2  s .  c  o m
    System.out.println();
}

From source file:Main.java

public static Map<String, Double> parseDoubleJsonMap(JSONObject object) throws JSONException {
    Map<String, Double> map = new ArrayMap<String, Double>();
    Iterator<String> keys = object.keys();
    while (keys.hasNext()) {
        String key = keys.next();
        map.put(key, object.getDouble(key));
    }//from www . jav  a 2 s . c  o  m
    return map;
}