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

Mapreverse(Map source)
Returns a new map that contains the reverse of the given map.
Map<T, T> target = new HashMap<T, T>();
for (Entry<T, T> entry : source.entrySet()) {
    target.put(entry.getValue(), entry.getKey());
return target;
HashMap>reverse_map(Map map)
"{:a 1 :b 1 :c 2} -> {1 [:a :b] 2 :c}"
HashMap<V, List<K>> rtn = new HashMap<V, List<K>>();
if (map == null) {
    return rtn;
for (Entry<K, V> entry : map.entrySet()) {
    K key = entry.getKey();
    V val = entry.getValue();
    List<K> list = rtn.get(val);
...
HashMap>reverse_map(Map map)
"{:a 1 :b 1 :c 2} -> {1 [:a :b] 2 :c}"
HashMap<V, List<K>> rtn = new HashMap<V, List<K>>();
if (map == null) {
    return rtn;
for (Entry<K, V> entry : map.entrySet()) {
    K key = entry.getKey();
    V val = entry.getValue();
    List<K> list = rtn.get(val);
...
MapreverseKeyAndValue(Map map)
reverse Key And Value
Map reverseMap = new HashMap();
for (Entry entry : (Set<Entry>) map.entrySet()) {
    reverseMap.put(entry.getValue(), entry.getKey());
return reverseMap;
MapreverseLabelMap(Map labelMap)
reverse Label Map
Map<Double, T> revMap = new HashMap<Double, T>();
for (T k : labelMap.keySet()) {
    revMap.put(labelMap.get(k), k);
return revMap;
HashMapreverseMap(List listSeq)
"[[:a 1] [:b 1] [:c 2]} -> {1 [:a :b] 2 :c}" Reverses an assoc-list style Map like reverseMap(Map...)
HashMap<Object, List<Object>> rtn = new HashMap();
if (listSeq == null) {
    return rtn;
for (Object entry : listSeq) {
    List listEntry = (List) entry;
    Object key = listEntry.get(0);
    Object val = listEntry.get(1);
...
MapreverseMap(Map map)
Returns a map where the keys are the values of the map argument and the values are the corresponding keys.
HashMap<V, K> reversed = new HashMap<V, K>();
Set<Entry<K, V>> entries = map.entrySet();
for (Entry<K, V> entry : entries) {
    reversed.put(entry.getValue(), entry.getKey());
return reversed;
MapreverseMap(Map map)
reverse Map
Map<V, K> ret = new HashMap<V, K>();
for (K key : map.keySet()) {
    ret.put(map.get(key), key);
return ret;
MapreverseMap(Map map)
reverse Map
Map<V, K> ret = new HashMap<V, K>();
for (K key : map.keySet()) {
    ret.put(map.get(key), key);
return ret;
HashMapreverseMap(Map map)
Reverses a map into a HashMap .
HashMap<V, K> result = new HashMap<V, K>();
for (Map.Entry<K, V> entry : map.entrySet()) {
    V key = entry.getValue();
    if (result.containsKey(key)) {
        throw new IllegalArgumentException("Key already present.");
    result.put(key, entry.getKey());
return result;