List of usage examples for java.util Set iterator
Iterator<E> iterator();
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. jav a 2 s . co m } return null; }
From source file:Main.java
public static ArrayList<String> getHashMap(HashMap<String, String> hm) { ArrayList<String> a = new ArrayList<String>(); Set s = hm.entrySet(); Iterator it = s.iterator(); while (it.hasNext()) { Map.Entry m = (Map.Entry) it.next(); a.add(m.getKey() + "\t" + m.getValue()); }// w w w.j a va 2 s. c om return a; }
From source file:Main.java
public static void print(Set set) { Iterator iter = set.iterator(); System.out.println("Printing Set: "); while (iter.hasNext()) { System.out.println(" " + iter.next()); }/*from w ww .ja v a 2 s .co m*/ }
From source file:Main.java
@SuppressWarnings("rawtypes") public static String getKeyByValue(Map<?, String> hm, String value) { Set<?> s = hm.entrySet(); Iterator<?> it = s.iterator(); while (it.hasNext()) { Map.Entry m = (Map.Entry) it.next(); if (m.getValue().equals(value)) return m.getKey() + ""; }//w w w . j av a 2 s . c om return null; }
From source file:Main.java
@SuppressWarnings("rawtypes") public static Map<Integer, String> swapStrKeysAndIntValues(Map<String, Integer> hm) { HashMap<Integer, String> nhm = new HashMap<Integer, String>(); Set<?> s = hm.entrySet(); Iterator<?> it = s.iterator(); while (it.hasNext()) { Map.Entry m = (Map.Entry) it.next(); nhm.put((Integer) m.getValue(), (String) m.getKey()); }//from w ww. j av a2s .c om return nhm; }
From source file:Main.java
@SuppressWarnings("rawtypes") public static Map<String, Integer> swapIntKeysAndStrValues(Map<Integer, String> hm) { HashMap<String, Integer> nhm = new HashMap<String, Integer>(); Set<?> s = hm.entrySet(); Iterator<?> it = s.iterator(); while (it.hasNext()) { Map.Entry m = (Map.Entry) it.next(); nhm.put((String) m.getValue(), (Integer) m.getKey()); }/*from w w w . ja v a2 s . c om*/ return nhm; }
From source file:SetUtils.java
public static boolean containsAny(Set a, Set b) { for (Iterator iter = b.iterator(); iter.hasNext();) { if (a.contains(iter.next())) { return true; }// ww w .ja v a 2s .c o m } return false; }
From source file:Main.java
@SuppressWarnings("rawtypes") public static Map<String, String> swapStrKeysAndStrValues(Map<String, ?> hm) { HashMap<String, String> nhm = new HashMap<String, String>(); Set<?> s = hm.entrySet(); Iterator<?> it = s.iterator(); while (it.hasNext()) { Map.Entry m = (Map.Entry) it.next(); nhm.put((String) m.getValue(), (String) m.getKey()); }/*from w w w . ja v a 2s .c o m*/ return nhm; }
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 w w. j ava2 s . co m*/ }
From source file:Main.java
@SuppressWarnings("rawtypes") public static List<String> keysToList(Map<?, ?> map) { List<String> list = new ArrayList<String>(); Set<?> set = map.entrySet(); Iterator<?> iter = set.iterator(); while (iter.hasNext()) { Map.Entry m = (Map.Entry) iter.next(); list.add("" + m.getKey()); }/*from w ww . java 2 s . c o m*/ return list; }