List of usage examples for java.util Iterator next
E next();
From source file:Main.java
public static Map<String, Boolean> parseBooleanJsonMap(JSONObject object) throws JSONException { Map<String, Boolean> map = new ArrayMap<String, Boolean>(); Iterator<String> keys = object.keys(); while (keys.hasNext()) { String key = keys.next(); map.put(key, object.getBoolean(key)); }/*from w w w . ja va 2s. co m*/ return map; }
From source file:Main.java
public static Collection and(Collection collection1, Collection collection2) { Vector completeList = new Vector(); if (collection2 == null) return completeList; Iterator i = collection2.iterator(); while (i.hasNext()) { Object addlItem = i.next(); if (collection1.contains(addlItem) == true) { completeList.addElement(addlItem); }/*from w ww . jav a2s . co m*/ } return completeList; }
From source file:Main.java
public static ArrayList<String> getHashMap(HashMap<String, String> hm) { ArrayList<String> a = new ArrayList<String>(); Set s = hm.entrySet();/*from ww w. ja v a 2s. com*/ Iterator it = s.iterator(); while (it.hasNext()) { Map.Entry m = (Map.Entry) it.next(); a.add(m.getKey() + "\t" + m.getValue()); } return a; }
From source file:Main.java
/** * Get comma separated string from collection * //w w w.ja va2s.com * @param strings * @return */ public static String getCommaSeparatedString(Collection<String> strings) { if (strings != null && !strings.isEmpty()) { Iterator<String> it = strings.iterator(); StringBuilder sb = new StringBuilder(it.next()); while (it.hasNext()) { sb.append("," + it.next()); } return sb.toString(); } else { return null; } }
From source file:Main.java
License:asdf
public static <K, V> Object getKey(Map<K, V> in, V value) { Set<K> key = in.keySet(); Iterator<K> keyIterator = key.iterator(); while (keyIterator.hasNext()) { K valueObject = (K) keyIterator.next(); if (in.get(valueObject).equals(value)) { return valueObject; }/*from www . j a v a2 s . co m*/ } return null; }
From source file:Main.java
@SuppressWarnings("rawtypes") public static String getKeyByValue(Map<?, String> hm, String value) { Set<?> s = hm.entrySet(); Iterator<?> it = s.iterator(); while (it.hasNext()) { Map.Entry m = (Map.Entry) it.next(); if (m.getValue().equals(value)) return m.getKey() + ""; }//from ww w. j a v a 2s .c o m return null; }
From source file:Main.java
/** * Creates new collection that contains only element whose string * representation starts with prefix It is parameterized. * /*from ww w . j a va2 s . c om*/ * @param c * raw collection to create prefixed collection from * @param prefix * to use as filter * @return collection without nulls */ public static <T> Collection<T> withPrefix(Collection<T> c, String prefix) { Collection<T> prefixed = new ArrayList<T>(); Iterator<T> iterator = c.iterator(); while (iterator.hasNext()) { T o = iterator.next(); if (o != null && o.toString().startsWith(prefix)) { prefixed.add(o); } } return prefixed; }
From source file:Main.java
/** * Returns a {@link Collection} containing <tt><i>a</i> - <i>b</i></tt>. The * cardinality of each element <i>e</i> in the returned {@link Collection} * will be the cardinality of <i>e</i> in <i>a</i> minus the cardinality of * <i>e</i> in <i>b</i>, or zero, whichever is greater. * //from w w w . j a v a 2s . c o m * @see Collection#removeAll */ public static Collection subtract(final Collection a, final Collection b) { ArrayList list = new ArrayList(a); Iterator it = b.iterator(); while (it.hasNext()) { list.remove(it.next()); } return list; }
From source file:Main.java
public static String implode(final Iterable<?> pieces, final String glue) { if (pieces == null) { return ""; }//from w ww . ja v a 2s . co m final StringBuilder resBuf = new StringBuilder(100); final Iterator<?> iter = pieces.iterator(); resBuf.append(iter.next().toString()); while (iter.hasNext()) { resBuf.append(glue); resBuf.append(iter.next().toString()); } return resBuf.toString(); }
From source file:Main.java
@SuppressWarnings("rawtypes") public static Map<Integer, String> swapStrKeysAndIntValues(Map<String, Integer> hm) { HashMap<Integer, String> nhm = new HashMap<Integer, String>(); Set<?> s = hm.entrySet(); Iterator<?> it = s.iterator(); while (it.hasNext()) { Map.Entry m = (Map.Entry) it.next(); nhm.put((Integer) m.getValue(), (String) m.getKey()); }//from w ww . j av a2 s . c o m return nhm; }