Java Map Reverse reverse(Map map)

Here you can find the source of reverse(Map map)

Description

Reverse.

License

Apache License

Parameter

Parameter Description
map the map

Return

the map< k, v>

Declaration

public static <K extends Comparable<K>, V> Map<K, V> reverse(Map<K, V> map) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Collections;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Main {
    /**/*from  w w w  .  j  a  v  a2  s  .c  o m*/
     * Reverse.
     * 
     * @param map
     *            the map
     * 
     * @return the map< k, v>
     */
    public static <K extends Comparable<K>, V> Map<K, V> reverse(Map<K, V> map) {
        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);
    }
}

Related

  1. reverse(Map source, Map target)
  2. reverse(Map source, Map target)
  3. reverse(Map in)
  4. reverse(Map kvMap)
  5. reverse(Map map)
  6. reverse(Map source, Map target)
  7. reverse(Map source)
  8. reverse(Map source)
  9. reverse_map(Map map)