List of usage examples for java.util Iterator hasNext
boolean hasNext();
From source file:Main.java
public static ArrayList<String> getHashMap(HashMap<String, String> hm) { ArrayList<String> a = new ArrayList<String>(); Set<Map.Entry<String, String>> s = hm.entrySet(); Iterator<Map.Entry<String, String>> it = s.iterator(); while (it.hasNext()) { Map.Entry<String, String> m = (Map.Entry<String, String>) it.next(); a.add(m.getKey() + "\t" + m.getValue()); }// w ww. j a v a 2 s . com return a; }
From source file:Main.java
public static void dumpIntent(Intent i) { Bundle bundle = i.getExtras();/*from w w w. ja va 2 s . c o m*/ if (bundle != null) { Set<String> keys = bundle.keySet(); Iterator<String> it = keys.iterator(); while (it.hasNext()) { String key = it.next(); } } }
From source file:Main.java
public static <T> T first(Collection<T> c) { if (isEmpty(c)) return null; if (c instanceof List) return (T) ((List<T>) c).get(0); Iterator<T> iter = c.iterator(); if (iter.hasNext()) { return iter.next(); }/*from ww w. jav a 2 s . co m*/ return null; }
From source file:Main.java
public static String implode(Iterator it) { StringBuilder sb = new StringBuilder(); while (it.hasNext()) { sb.append(it.next());/*from w ww .j ava2 s.c om*/ sb.append(", "); } return sb.toString().replaceAll(", +$", ""); }
From source file:Main.java
public static ArrayList<String> getHashMap2(HashMap<String, Integer> hm) { ArrayList<String> a = new ArrayList<String>(); Set<Map.Entry<String, Integer>> s = hm.entrySet(); Iterator<Map.Entry<String, Integer>> it = s.iterator(); while (it.hasNext()) { Map.Entry<String, Integer> m = (Map.Entry<String, Integer>) it.next(); a.add(m.getKey() + "\t" + m.getValue()); }//from w ww. j a v a2 s .c om return a; }
From source file:Main.java
private static void setSizes(java.util.List<JComponent> aComponents, Dimension aDimension) { Iterator<JComponent> compsIter = aComponents.iterator(); while (compsIter.hasNext()) { JComponent comp = (JComponent) compsIter.next(); comp.setPreferredSize((Dimension) aDimension.clone()); comp.setMaximumSize((Dimension) aDimension.clone()); }/* www . java 2 s. c om*/ }
From source file:Main.java
/** * @param iterable//from w ww. j av a 2 s . co m * @return null if the iterable element is null or if there are no elements in it or the first element if it does */ public static <E> E first(final Iterable<E> iterable) { if (null == iterable) { return null; } final Iterator<E> it = iterable.iterator(); if (!it.hasNext()) { return null; } return it.next(); }
From source file:Main.java
public static Map<Object, Object> copySafelyToObjectToObjectMap(Map<?, ?> map) { Map<Object, Object> castedCopy = new LinkedHashMap<Object, Object>(); if (map == null) { return castedCopy; }/* w w w .ja v a 2 s .c o m*/ Iterator<?> it = map.keySet().iterator(); while (it.hasNext()) { Object nextKey = it.next(); castedCopy.put(nextKey, map.get(nextKey)); } return castedCopy; }
From source file:Main.java
public static boolean equalsSet(Collection c1, Collection c2) { boolean equals; if (c1 == null) { equals = (c2 == null);/*from w ww. j a v a 2 s . c om*/ } else if (c2 == null) { equals = false; } else if (c1.size() == c2.size()) { equals = true; Iterator iterC1 = c1.iterator(); while (equals && iterC1.hasNext()) { Object o1 = iterC1.next(); equals = c2.contains(o1); } } else { equals = false; } return equals; }
From source file:Main.java
/** * not tested yet// ww w . j a v a 2 s.co m * * @param map * @return */ public static List<Object> getMapValues(Map<Object, Object> map) { List<Object> valuemaplist = new ArrayList<Object>(); Iterator<Object> iterator = map.keySet().iterator(); while (iterator.hasNext()) { valuemaplist.add(map.get(iterator.next())); } return valuemaplist; }