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

/**
 * Returns the number of occurrences of <i>obj</i> in <i>col</i>.
 *///from   ww w .ja  v  a  2s  .  c om
public static int cardinality(Object obj, final Collection col) {
    int count = 0;
    Iterator it = col.iterator();
    while (it.hasNext()) {
        Object elt = it.next();
        if ((null == obj && null == elt) || obj.equals(elt)) {
            count++;
        }
    }
    return count;
}

From source file:Main.java

/**
 * Creates new collection that does not contain nulls. Does not change input
 * collection. It uses raw collection - not parameterized.
 * {@link SuppressWarnings} annotation is added to avoid IDE to report
 * rawtypes and unchecked warnings./*  w w  w.  j  a  va  2 s .  c om*/
 * 
 * @param c
 *            raw collection to create cleaned collection from.
 * @return collection without nulls
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Collection toCleanedRaw(Collection c) {
    ArrayList cleaned = new ArrayList();
    Iterator iterator = c.iterator();
    while (iterator.hasNext()) {
        Object e = iterator.next();
        if (e != null) {
            cleaned.add(e);
        }
    }
    return cleaned;
}

From source file:Main.java

public static Map<String, String> bundleToMap(Bundle extras) {
    Map<String, String> map = new HashMap<String, String>();

    Set<String> ks = extras.keySet();
    Iterator<String> iterator = ks.iterator();
    while (iterator.hasNext()) {
        String key = iterator.next();
        map.put(key, extras.getString(key));
    }/*from ww  w .j a  v a  2s.c o  m*/
    return map;
}

From source file:Main.java

public static HashSet<String> intersectionSet(HashSet<String> setA, HashSet<String> setB) {
    HashSet<String> intersectionSet = new HashSet<String>();
    Iterator<String> iterA = setA.iterator();
    while (iterA.hasNext()) {
        String tempInner = iterA.next();
        if (setB.contains(tempInner)) {
            intersectionSet.add(tempInner);
        }/*ww w .jav a2  s  .  com*/
    }
    return intersectionSet;
}

From source file:Main.java

/**
 * Creates new collection that contains only element whose string
 * representation starts with prefix It uses raw collection - not
 * parameterized. There is no {@link SuppressWarnings} annotation so IDE
 * will probably report rawtype and/or unchecked warnings.
 * /*w  ww.j a v  a 2 s  .  c o m*/
 * @param c
 *            raw collection to create prefixed collection from
 * @param prefix
 *            to use as filter
 * @return collection without nulls
 */
public static Collection withPrefixRaw(Collection c, String prefix) {
    Collection prefixed = new ArrayList();
    Iterator iterator = c.iterator();
    while (iterator.hasNext()) {
        Object o = iterator.next();
        if (o != null && o.toString().startsWith(prefix)) {
            prefixed.add(o);
        }
    }
    return prefixed;
}

From source file:Main.java

/**
 * Returns an arbitrary element from the given collection.
 * /*w w w .  j  a v a2s .c om*/
 * @param collection
 *        to retrieve the element from
 * @return an arbitrary element or <tt>null</tt> if the collection is empty
 */
public static <T> T getAny(final Collection<T> collection) {
    final Iterator<T> iterator = collection.iterator();
    if (iterator.hasNext()) {
        return iterator.next();
    }

    return null;
}

From source file:Main.java

public static void deleteDuplicate(List<Integer> list) {
    List<Integer> tempList = new ArrayList<Integer>();

    Iterator<Integer> iter = list.iterator();
    while (iter.hasNext()) {
        Integer current = iter.next();
        if (tempList.contains(current)) {
            iter.remove();//  w w  w . j av a  2s .  co m
        } else {
            tempList.add(current);
        }
    }
}

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());
        if (iter.hasNext()) {
            buffer.append(delimiter);/*from   ww w.  ja v a  2  s . c om*/
        }
    }
    return buffer.toString();
}

From source file:Main.java

public static String Map2StringPrettyPrint(Hashtable m) {
    String retString = "";
    Iterator iter = m.keySet().iterator();

    while (iter.hasNext()) {
        String key = (String) iter.next();
        retString += key + " = " + m.get(key) + "\n";
    }//from   www  .j av  a  2 s.  c o m

    return (retString.trim());
}

From source file:Main.java

private static String buildQueryString(String method, Map<String, String> args) {
    String qry = buildQueryString(method);
    Iterator it = args.entrySet().iterator();
    while (it.hasNext()) {
        String key = (String) it.next();
        String val = args.get(key);
        qry = qry.concat("?").concat(key).concat("=").concat(val);
    }/*from   w  ww.  jav  a 2  s . c  om*/
    return qry;
}