List of usage examples for java.util Iterator next
E next();
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 v a2 s .c om * @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
public static <T> T getFirstNonNull(Collection<T> c) { T ret = null;//from ww w.j av a2 s . c o m Iterator<T> it = c.iterator(); while (it.hasNext() && ret == null) { T t = it.next(); if (t != null) ret = t; } return ret; }
From source file:Main.java
public static <T> T min(Iterator<? extends T> iterator, Comparator<T> comparator) { T next, candidate = iterator.next(); while (iterator.hasNext()) { if (comparator.compare(next = iterator.next(), candidate) < 0) { candidate = next;//from w w w.j a v a 2 s.c om } } return candidate; }
From source file:Main.java
public static <T> T nth(Iterable<T> coll, int which) { Iterator<T> it = coll.iterator(); T ret = null;//from www. j a v a2 s . c o m while (which-- >= 0) ret = it.next(); return ret; }
From source file:Main.java
private static String reconstruireDonnee(Vector<Integer> vectBit) { String donnee = ""; //On ajoute le nouvel encodage dans le String "ligne" vide ci-haut Iterator<Integer> it = vectBit.iterator(); while (it.hasNext()) { donnee += it.next(); }//from w ww . j a v a2 s . co m return donnee; }
From source file:Main.java
public static <T> List<T> intersection(Collection<T> a, Collection<T> b) { ArrayList list = new ArrayList(); Iterator i$ = a.iterator(); while (i$.hasNext()) { Object element = i$.next(); if (b.contains(element)) { list.add(element);// w w w. j a va 2 s .c o m } } return list; }
From source file:Main.java
/** * Answer a set containing all elements that are both in source and in query * Delete these elements from source Creation date: (13.10.2002 16:23:00) * // ww w .j a v a 2 s . c o m * @return java.util.Set * @param source * java.util.Set * @param elements * java.util.Collection */ public static Set extractFrom(Set source, Collection query) { Set answer = new HashSet(); Iterator i = query.iterator(); while (i.hasNext()) { Object o = i.next(); if (source.remove(o)) { answer.add(o); } } return answer; }
From source file:Main.java
public static String toString(Collection<?> list, String split) { if (list == null) { return null; }/*from w w w. jav a 2 s . c o m*/ StringBuffer rs = new StringBuffer(); Iterator<?> it = list.iterator(); while (it.hasNext()) { rs.append(it.next()); if (it.hasNext()) { rs.append(split); } } return rs.toString(); }
From source file:Main.java
public static Object getFirstObject(Collection<?> collection) { Iterator<?> iterator = collection.iterator(); if (iterator.hasNext()) { return iterator.next(); } else {// ww w . j av a 2 s . c o m return null; } }
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; }//from ww w. j a v a2 s. c o m return false; }