List of usage examples for java.util Map entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:Main.java
public static String MapToUrl(Map<?, ?> data) { StringBuffer queryString = new StringBuffer(); for (Map.Entry<?, ?> pair : data.entrySet()) { queryString.append(pair.getKey() + "="); queryString.append(pair.getValue() + "&"); }//from w ww . j a v a 2 s . co m if (queryString.length() > 0) { queryString.deleteCharAt(queryString.length() - 1); } return queryString.toString(); }
From source file:Main.java
public static <K, G> Map<K, G> reverseMap(Map<String, K> keyIdMap, Map<String, G> keyValueMap) { Map<K, G> ret = new HashMap<K, G>(); for (Entry<String, G> entry : keyValueMap.entrySet()) { K id = keyIdMap.get(entry.getKey()); ret.put(id, entry.getValue());/*from w w w.j a v a2 s .com*/ } return ret; }
From source file:Main.java
public static <T extends Comparable> List<Entry<String, T>> sortMapDesc(Map<String, T> keywordMap) { List<Entry<String, T>> arrayList = new ArrayList<Entry<String, T>>(keywordMap.entrySet()); Collections.sort(arrayList, new Comparator<Entry<String, T>>() { @Override//w w w . ja v a 2 s . c o m public int compare(Entry<String, T> e1, Entry<String, T> e2) { return (e2.getValue()).compareTo(e1.getValue()); } }); return arrayList; }
From source file:Main.java
public static <T extends Comparable> List<Entry<String, T>> sortMapAsc(Map<String, T> keywordMap) { List<Entry<String, T>> arrayList = new ArrayList<Entry<String, T>>(keywordMap.entrySet()); Collections.sort(arrayList, new Comparator<Entry<String, T>>() { @Override/*from w ww . j a va 2 s .c o m*/ public int compare(Entry<String, T> e1, Entry<String, T> e2) { return (e1.getValue()).compareTo(e2.getValue()); } }); return arrayList; }
From source file:Main.java
/** * // ww w . j a v a 2 s .c o m * @param vehiclesMap */ public static void print(Map<String, List<String>> map) { for (Iterator<Entry<String, List<String>>> iterator = map.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, List<String>> entry = (Map.Entry<String, List<String>>) iterator.next(); String key = entry.getKey(); List<String> values = entry.getValue(); System.out.println(key); for (String string : values) { System.out.println("\t" + string); } } // System.out.println("Lista: " + vehicles.size()); }
From source file:Main.java
public static String serializeAttributes(Map<String, String> attributes) { String serialization = ""; for (Entry<String, String> entry : attributes.entrySet()) { serialization = concatKeyValue(serialization, entry.getKey(), entry.getValue()); }/*from w w w.j a va2 s . c o m*/ return serialization; }
From source file:Main.java
/** * Sorts a Map by it's value/* w w w .j a va2 s. c om*/ * * @param map Map * @param <K> Key * @param <V> Value * @return The sorted map */ public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) { Map<K, V> result = new LinkedHashMap<>(); Stream<Map.Entry<K, V>> st = map.entrySet().stream(); st.sorted(Comparator.comparing(Map.Entry::getValue)) .forEachOrdered(e -> result.put(e.getKey(), e.getValue())); return result; }
From source file:Main.java
public static <T extends Object> List<T> map2list(Map<String, T> maps) { List<T> list = new ArrayList<T>(); Iterator<Entry<String, T>> iterator = maps.entrySet().iterator(); while (iterator.hasNext()) { Entry<String, T> entry = iterator.next(); list.add(entry.getValue());/* w w w .j a v a 2 s . c om*/ } return list; }
From source file:Main.java
public final static <K, V> String keyJoin(Map<K, V> map, String separator) { StringBuilder sb = new StringBuilder(); for (Map.Entry<K, V> entry : map.entrySet()) { sb.append(String.valueOf(entry.getKey())).append(separator); }//from ww w .j a va 2 s.co m return sb.toString().substring(0, sb.toString().length() - separator.length()); }
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()); }// ww w.j a v a2 s . co m return nhm; }