List of usage examples for java.util Iterator hasNext
boolean hasNext();
From source file:Main.java
/** * Get key value of map in String// w ww . j a v a 2 s.c o m * * @version 1.0 * @author pankajbharti */ @SuppressWarnings("rawtypes") public static String getKeyValue(Map map) { StringBuilder str = new StringBuilder(""); Set keySet = map.entrySet(); Iterator itr = keySet.iterator(); while (itr.hasNext()) { Map.Entry entry = (Map.Entry) itr.next(); str.append(entry.getKey() + " : " + entry.getValue() + "\n" + "\t \t \t \t \t"); } return str.toString(); }
From source file:Main.java
/** * Fold up a collection into a string./*from ww w. j a v a2s . co m*/ */ public static String join(Collection a_collection, String a_sDelimiter) /* --------------------------------------------------------------- d1 17-Oct-2006 Adam Bones Created ----------------------------------------------------------------- */ { StringBuffer buffer = new StringBuffer(); Iterator it = a_collection.iterator(); while (it.hasNext()) { buffer.append(it.next()); if (it.hasNext()) { buffer.append(a_sDelimiter); } } return buffer.toString(); }
From source file:Main.java
/** * Get the first element of a an {@link Iterable} in iteration order, or null if empty. * * @param <T> the type//from ww w. ja va 2 s . co m * @param iterable the thing to get something from. * @return the first thing the iterator spits out. May */ public static <T> T first(@Nonnull final Iterable<? extends T> iterable) { final Iterator<? extends T> iterator = iterable.iterator(); return (iterator.hasNext()) ? iterator.next() : null; }
From source file:Main.java
private static String toString(Collection message) { Iterator it = message.iterator(); if (!it.hasNext()) return "[]"; StringBuilder sb = new StringBuilder(); sb.append('['); for (;;) {/*from www . j a va 2s . co m*/ Object e = it.next(); sb.append(e); if (!it.hasNext()) return sb.append(']').toString(); sb.append(',').append('\n').append(' '); } }
From source file:Main.java
private static List getMainProcessNames(List list) { ArrayList arraylist = new ArrayList(); Iterator iterator = list.iterator(); do {//from ww w . j av a2 s. c o m if (!iterator.hasNext()) break; String s = (String) iterator.next(); int i = s.indexOf(":"); if (i > 0) arraylist.add(s.substring(0, i)); } while (true); return arraylist; }
From source file:Main.java
public static Map<String, String> parse(JSONObject json, Map<String, String> out) throws JSONException { Iterator<String> keys = json.keys(); while (keys.hasNext()) { String key = keys.next(); String val = null; try {/*from w w w .java 2 s .c om*/ JSONObject value = json.getJSONObject(key); parse(value, out); } catch (Exception e) { val = json.getString(key); } if (val != null) { out.put(key, val); } } return out; }
From source file:Main.java
public static <T> boolean doCompare(Collection<T> c1, Collection<T> c2) { if (c1 == null && c2 == null) { return true; }// w ww.j a v a 2s .c om if (c1 == null || c2 == null) { return false; } if (c1.size() != c2.size()) { return false; } Iterator<T> it = c1.iterator(); while (it.hasNext()) { if (!c2.contains(it.next())) { return false; } } return true; }
From source file:Main.java
public static <T> T getAt(Collection<T> col, int index) { if (col instanceof List) return ((List<T>) col).get(index); int i;/* www. j a v a 2 s. c om*/ Iterator<T> it; for (i = 0, it = col.iterator(); i < index && it.hasNext(); it.next()) ; return it.hasNext() ? it.next() : null; }
From source file:Main.java
static void appendJson(JSONObject json, JSONObject jsonToAppend) { if (jsonToAppend == null) return;//from w ww .j ava2s .co m try { Iterator<String> it = jsonToAppend.keys(); while (it.hasNext()) { String key = it.next(); json.put(key, jsonToAppend.get(key)); } } catch (JSONException e) { e.printStackTrace(); } }
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();/*w w w .j av a2s. co m*/ V value = source.get(key); target.put(value, key); } }