Example usage for java.util Iterator hasNext

List of usage examples for java.util Iterator hasNext

Introduction

In this page you can find the example usage for java.util Iterator hasNext.

Prototype

boolean hasNext();

Source Link

Document

Returns true if the iteration has more elements.

Usage

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();//from  w w w.j  a  va  2 s. co  m
        Log.d(TAG, "dump " + key + " : " + String.valueOf(map.get(key)));
    }
}

From source file:Main.java

public static void printMapBySet(Map map) {
    Set<String> ketSet = map.keySet();
    Iterator<String> iterator = ketSet.iterator();
    while (iterator.hasNext()) {
        String key = iterator.next();
        String value = (String) map.get(key);
        Log.i(TAG, "----key = " + key + ",value = " + value);
    }/*from ww w  . ja v a2  s  . co  m*/

}

From source file:Main.java

public static String join(Collection<String> collection, String delimiter) {
    StringBuffer buffer = new StringBuffer();
    Iterator<String> iter = collection.iterator();
    while (iter.hasNext()) {
        buffer.append(iter.next());//from  w  w  w  . ja  v  a  2 s.c  o  m
        if (iter.hasNext()) {
            buffer.append(delimiter);
        }
    }
    return buffer.toString();
}

From source file:Main.java

public static <T> void cleanNulls(Collection<T> c) {
    Iterator<T> it = c.iterator();
    try {//  w  w w . j  ava2 s  .com
        while (it.hasNext())
            if (it.next() == null)
                c.remove(null);
    } catch (NullPointerException e) {
        // Does not permit nulls, it should be ok
    }
}

From source file:Main.java

public static <T> T getByIndex(Iterable<T> iterable, int index) {
    T el = null;//from  w w w.  j ava 2 s  .  com
    Iterator<T> it = iterable.iterator();
    for (int i = 0; it.hasNext(); i++) {
        T cur = it.next();
        if (i == index) {
            el = cur;
            break;
        }
    }
    return el;
}

From source file:Main.java

/**
 * Adds all elements that a given {@link Iterator} provides to a given
 * {@link Collection} of appropriate type
 * //from  w  w  w.j  a  v a 2s.co  m
 * @param targetCollection
 *           the {@link Collection} where to add the elements
 * @param sourceIterator
 *           the {@link Iterator} where to get the elements from
 * @param <T>
 *           the type of elements to transfer
 */
public static <T> void addAll(final Collection<? super T> targetCollection,
        final Iterator<? extends T> sourceIterator) {
    while (sourceIterator.hasNext()) {
        targetCollection.add(sourceIterator.next());
    }
}

From source file:Main.java

public static List list(Iterator ite) {
    ArrayList ret = new ArrayList();
    while (ite.hasNext()) {
        Object o = ite.next();/*from w  w  w.  j av a 2s  .c  o  m*/
        ret.add(o);
    }
    return ret;
}

From source file:Main.java

/**
 *//*from w  w w  . ja v  a  2  s .  com*/
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 boolean containsIgnoreCase(List<String> l, String s) {
    Iterator<String> it = l.iterator();
    while (it.hasNext()) {
        if (it.next().equalsIgnoreCase(s))
            return true;
    }// w  ww . jav  a 2  s  . c  o m
    return false;
}

From source file:Main.java

/** Write all Identifiables that we contain to os.  The total
 * length must be written before this method is called.
 *//*www . j  av a2  s . c o m*/
public static void writeIdentifiableSequence(List container, OutputStream os) {
    os.write_long(container.size());
    Iterator iter = container.iterator();
    while (iter.hasNext()) {
        Identifiable obj = (Identifiable) (iter.next());
        os.write_long(obj.getId());
        obj.write(os);
    }
}