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 String toIdListString(Collection<Long> ids) {
    StringBuilder response = new StringBuilder();
    Iterator<Long> i = ids.iterator();
    while (i.hasNext()) {
        response.append(i.next());
        if (i.hasNext())
            response.append(",");
    }/*from ww  w .jav  a  2 s  .  c o m*/
    return response.toString();
}

From source file:Main.java

public static void dumpCurrentSharedPrerence(SharedPreferences pref) {
    Map<String, ?> map = pref.getAll();
    Iterator<String> ite = map.keySet().iterator();
    while (ite.hasNext()) {
        String key = ite.next();
        Log.d(TAG, "dump " + key + " : " + String.valueOf(map.get(key)));
    }/*w w w. j a  v  a 2 s . c  om*/
}

From source file:Main.java

/**
 *//* w w  w .j av  a 2 s  . c  om*/
public static String[] getTextElements(List<Element> elements) throws Exception {
    ArrayList<String> list = new ArrayList<String>();
    Iterator<Element> iter = elements.iterator();
    while (iter.hasNext()) {
        String s = iter.next().getFirstChild().getTextContent();
        list.add(s);
    }
    return list.toArray(new String[0]);
}

From source file:Main.java

public static <E> void addAll(Collection<E> collection, Iterator<? extends E> iterator) {
    while (iterator.hasNext()) {
        collection.add(iterator.next());
    }//from www  .j av a2s . com
}

From source file:Main.java

public static <T> Map<T, Integer> getCardinalityMap(final Collection<T> coll) {
    if (coll == null) {
        return null;
    }//  w  w w.j a  va 2  s.  c  o m

    Map<T, Integer> result = new HashMap<T, Integer>();
    Iterator<T> it = coll.iterator();
    while (it.hasNext()) {
        T t = it.next();
        Integer count = result.get(t);
        if (count == null) {
            result.put(t, ONE);
        } else {
            result.put(t, new Integer(count.intValue() + 1));
        }
    }
    return result;
}

From source file:Main.java

public static <T> T first(Collection<T> list) {
    Iterator<T> iterator = list.iterator();
    if (iterator.hasNext()) {
        return iterator.next();
    }/*from ww  w. j a  v a 2  s  .co m*/
    return null;
}

From source file:Main.java

public static <T> List<T> toList(Iterator<T> it) {
    List<T> result = new ArrayList<T>();
    while (it.hasNext())
        result.add(it.next());
    return result;
}

From source file:Main.java

/** @return whether given coll contains all elements of other, using a naive/basic algorithm. */
public static boolean containsAll(Collection<?> coll, Collection<?> other) {
    Iterator<?> citer = other.iterator();
    while (citer.hasNext())
        if (!coll.contains(citer.next()))
            return false;
    return true;/* ww w . j a  v a 2 s.  c  om*/
}

From source file:Main.java

public static <T extends Collection<?>> void stripNulls(T collection) {
    Iterator<?> iterator = collection.iterator();
    while (iterator.hasNext()) {
        if (iterator.next() == null)
            iterator.remove();//ww w . j ava2  s  .co  m
    }
}

From source file:Main.java

/** Take key and value pairs from source and create map from value to key in target. */
public static <K, V> void reverse(Map<K, V> source, Map<V, K> target) {
    Iterator<K> i = source.keySet().iterator();
    while (i.hasNext()) {
        K key = i.next();
        V value = source.get(key);//from  ww w  .ja  va2  s.  co  m
        target.put(value, key);
    }
}