List of usage examples for java.util Iterator hasNext
boolean hasNext();
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();/* ww w .j av a 2 s. c o m*/ } else { tempList.add(current); } } }
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)); }/* w w w. j a v a 2 s .c om*/ return map; }
From source file:Main.java
public static String join(Iterator<String> strings, String sep) { if (!strings.hasNext()) return ""; String start = strings.next(); if (!strings.hasNext()) // only one, avoid builder return start; StringBuilder sb = new StringBuilder(64).append(start); while (strings.hasNext()) { sb.append(sep);/*from w w w .j av a 2 s .c o m*/ sb.append(strings.next()); } return sb.toString(); }
From source file:Main.java
public static final <E, F extends Collection<E>> F removeNulls(F collection) { Iterator<E> iterator = collection.iterator(); while (iterator.hasNext()) { if (iterator.next() == null) { iterator.remove();//from w ww. ja v a2 s . c o m } } return collection; }
From source file:Main.java
public static <T> T lastOrDefault(Iterable<T> source) { if (source == null || !source.iterator().hasNext()) return null; T result = null;// ww w . java2s. c om Iterator<T> it = source.iterator(); while (it.hasNext()) { result = it.next(); // source } return result; }
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 ww .j a v a 2 s . c o m*/ * * @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
protected static void checkExcludedEmail(Set excluded, String email) throws CertPathValidatorException { if (excluded.isEmpty()) { return;//ww w. j av a 2 s .c o m } String sub = email.substring(email.indexOf('@') + 1); Iterator it = excluded.iterator(); while (it.hasNext()) { String str = (String) it.next(); if (sub.endsWith(str)) { throw new CertPathValidatorException("Subject email address is from an excluded subtree"); } } }
From source file:Main.java
public static String toIdListString(Collection<Long> ids) { StringBuilder response = new StringBuilder(); Iterator<Long> i = ids.iterator(); while (i.hasNext()) { response.append(i.next());/* w w w . j a va 2 s .c o m*/ if (i.hasNext()) response.append(","); } return response.toString(); }
From source file:Main.java
public static String join(Iterable<? extends CharSequence> s, String delimiter) { Iterator<? extends CharSequence> iter = s.iterator(); if (!iter.hasNext()) return ""; StringBuilder buffer = new StringBuilder(iter.next()); while (iter.hasNext()) buffer.append(delimiter).append(iter.next()); return buffer.toString(); }
From source file:Main.java
public static void printMapList(List<Map> list) { Map map = null;//from www . j a v a 2 s . com 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()); } } }