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 printMapList(List<Map> list) {
    Map map = null;/* w w  w.  j  a va  2 s.  c o  m*/
    for (int i = 0; i < list.size(); i++) {
        map = list.get(i);
        Iterator iter = map.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            System.out.println(entry.getKey() + ": " + entry.getValue());
        }
    }
}

From source file:Main.java

public static List toList(Iterator iterator) {
    List list = new ArrayList();
    while (iterator.hasNext()) {
        list.add(iterator.next());
    }//w ww.  j ava2s  .  c o  m
    return list;
}

From source file:Main.java

public static int GetIndexFromCollectionUsingID(ArrayList list, String value) {
    Iterator Item = list.iterator();
    int index = -1;
    while (Item.hasNext()) {
        index++;// ww  w.  ja  v  a2s.  c o  m
        if (Item.next().toString().contains(value + " :"))
            return index;

    }
    return -1;
}

From source file:Main.java

/**
 * Returns the first element of the collection.
 * //from  w  w w.  j  a  v a  2 s .co m
 * @param <T>
 *            the element type
 * @param iterable
 *            the collection
 * @return the first element or null if the list is empty
 */
public static <T> T first(Iterable<T> iterable) {
    if (iterable instanceof Deque<?>)
        return ((Deque<T>) iterable).getFirst();
    if (iterable instanceof List<?>) {
        List<T> list = (List<T>) iterable;
        return list.isEmpty() ? null : list.get(0);
    }
    Iterator<T> iterator = iterable.iterator();
    return iterator.hasNext() ? iterator.next() : null;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <S, D extends S> D[] downcastToArray(Collection<S> source, Class<D> destClass) {
    D[] dest = (D[]) Array.newInstance(destClass, source.size());
    Iterator<S> it = source.iterator();
    for (int i = 0; i < dest.length; i++) {
        S s = it.next();
        if (destClass.isAssignableFrom(s.getClass()))
            dest[i] = (D) s;/*  w  ww.  j  a v  a 2 s.  co m*/
        else
            throw new IllegalArgumentException("Could not downcast element from class "
                    + s.getClass().getSimpleName() + " to " + destClass.getSimpleName());
    }
    return dest;
}

From source file:Main.java

public static int GetIndexFromCollection(ArrayList list, String value) {
    Iterator Item = list.iterator();
    int index = -1;
    while (Item.hasNext()) {
        index++;//  w w  w .  jav  a 2 s  .c  om
        if (Item.next().toString().equalsIgnoreCase(value))
            return index;

    }
    return -1;
}

From source file:Main.java

public static List changeSetToList(Set set) {
    Iterator setIter = set.iterator();
    List list = new ArrayList();
    while (setIter.hasNext()) {
        list.add(setIter.next());
    }//from  w ww  .j a v a2s. c o  m
    return list;
}

From source file:Main.java

public static String deepToString(final Collection<?> collection, final String left, final String right,
        final String sep) {
    final StringBuilder sb = new StringBuilder(3 * collection.size());
    sb.append(left);/*from   w ww.j av a 2  s.c  om*/
    final Iterator<?> iter = collection.iterator();
    if (iter.hasNext())
        sb.append(iter.next());
    while (iter.hasNext()) {
        sb.append(sep);
        sb.append(iter.next());
    }
    sb.append(right);
    return sb.toString();
}

From source file:Main.java

public static float[] asFloatArray(Collection<Float> collection) {
    float[] array = new float[collection.size()];
    Iterator<Float> iterator = collection.iterator();
    int i = 0;//from ww  w .  j  av  a2  s.  co m
    while (iterator.hasNext()) {
        array[i++] = iterator.next();
    }
    return array;
}