List of usage examples for java.util Iterator hasNext
boolean hasNext();
From source file:MainClass.java
protected static void print(String label, Collection c) { System.out.println("--------------" + label + "--------------"); Iterator it = c.iterator(); while (it.hasNext()) { System.out.println(it.next()); }//w w w . jav a 2s .com }
From source file:Main.java
public static boolean canWriteFormat(String formatName) { Iterator iter = ImageIO.getImageWritersByFormatName(formatName); return iter.hasNext(); }
From source file:Main.java
public static boolean canReadFormat(String formatName) { Iterator iter = ImageIO.getImageReadersByFormatName(formatName); return iter.hasNext(); }
From source file:Main.java
public static Object firstOrElse(Collection l, Object alt) { Iterator i = l.iterator(); if (i.hasNext()) return i.next(); return alt;//from w w w . j a v a 2s . co m }
From source file:Main.java
public static void printMap(Map<String, String> map) { Set<Map.Entry<String, String>> s = map.entrySet(); Iterator<Map.Entry<String, String>> it = s.iterator(); while (it.hasNext()) { Map.Entry<String, String> entry = (Map.Entry<String, String>) it.next(); String key = (String) entry.getKey(); String value = (String) entry.getValue(); System.out.println(key + " => " + value); }//from w ww. j ava 2 s. c o m }
From source file:Main.java
private static <T> void display(final Iterator<T> iterator) { while (iterator.hasNext()) { final T item; item = iterator.next();/*from w ww .j a va2s.c o m*/ System.out.println(item); } }
From source file:Main.java
private static String getFormatName(Object o) { try {/* w w w.ja v a 2s . c o m*/ ImageInputStream iis = ImageIO.createImageInputStream(o); Iterator iter = ImageIO.getImageReaders(iis); if (!iter.hasNext()) { return null; } ImageReader reader = (ImageReader) iter.next(); iis.close(); return reader.getFormatName(); } catch (IOException e) { } return null; }
From source file:Main.java
public static void iterableToList(Iterable iterable, List list) { Iterator it = iterable.iterator(); while (it.hasNext()) { list.add(it.next());//from w w w. j av a2 s . com } }
From source file:Main.java
/** * @throws IllegalArgumentException if an add operation "soft fails" (does not modify the collection) * @see Collection#addAll(Collection)// www .j av a2 s. co m */ public static <E> void addAllForce(Collection<E> collection, Iterator<? extends E> add) { while (add.hasNext()) { E next = add.next(); Preconditions.checkArgument(collection.add(next), "collection did not accept next element %s: %s", next, collection); } }
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; }//w w w. j ava 2 s .c o m } return null; }