Java Utililty Methods Map Reverse

List of utility methods to do Map Reverse

Description

The list of methods to do Map Reverse are organized into topic(s).

Method

Map>reverse(Map map)
reverse
Map<Y, List<X>> result = new HashMap<Y, List<X>>();
for (X key : map.keySet()) {
    Y value = map.get(key);
    if (!result.containsKey(value)) {
        result.put(value, new ArrayList<X>());
    result.get(value).add(key);
for (Y key : result.keySet()) {
    Collections.sort(result.get(key));
return result;
Mapreverse(final Map map)
Reverses a map (switches key and value types).
final Map<V, K> reversed = new HashMap<V, K>(map.size());
for (final Entry<K, V> e : map.entrySet()) {
    reversed.put(e.getValue(), e.getKey());
return reversed;
voidreverse(Map source, Map target)
reverse
for (Iterator it = source.keySet().iterator(); it.hasNext();) {
    Object key = it.next();
    target.put(source.get(key), key);
voidreverse(Map source, Map target)
reverse
for (Map.Entry entry : (Iterable<Map.Entry>) source.entrySet()) {
    target.put(entry.getValue(), entry.getKey());
LinkedHashMapreverse(Map in)
Reverses the order of a LinkedHashMap .
if (in == null)
    return null;
LinkedHashMap<K, V> m = new LinkedHashMap<K, V>();
List<K> keys = new ArrayList<K>(in.keySet());
List<V> values = new ArrayList<V>(in.values());
for (int i = in.size() - 1; i >= 0; i--)
    m.put(keys.get(i), values.get(i));
return m;
...
Mapreverse(Map kvMap)
reverse
Map<V, K> vkMap = new HashMap<V, K>(kvMap.size());
for (Map.Entry<K, V> e : kvMap.entrySet()) {
    vkMap.put(e.getValue(), e.getKey());
return vkMap;
Mapreverse(Map map)
Reversed a map, making the key value and the value key.
Map<V, K> reversedMap = new HashMap<V, K>();
for (Map.Entry<K, V> entry : map.entrySet()) {
    reversedMap.put(entry.getValue(), entry.getKey());
return reversedMap;
Mapreverse(Map map)
Reverse.
List<Map.Entry<K, V>> mapEntry = new LinkedList<Map.Entry<K, V>>(map.entrySet());
Collections.reverse(mapEntry);
LinkedHashMap<K, V> reversedMap = new LinkedHashMap<K, V>();
for (Iterator<Map.Entry<K, V>> it = mapEntry.iterator(); it.hasNext();) {
    Map.Entry<K, V> entry = it.next();
    reversedMap.put(entry.getKey(), entry.getValue());
return (reversedMap);
...
voidreverse(Map source, Map target)
Take key and value pairs from source and create map from value to key in target.
Iterator<K> i = source.keySet().iterator();
while (i.hasNext()) {
    K key = i.next();
    V value = source.get(key);
    target.put(value, key);
Mapreverse(Map source)
reverse
Map<String, Object> result = new LinkedHashMap<String, Object>();
List<String> keys = new ArrayList<String>(source.keySet());
Collections.reverse(keys);
for (String key : keys) {
    result.put(key, source.get(key));
return result;