Java List Sort mapTosortedScoreList(HashMap unSortedMap)

Here you can find the source of mapTosortedScoreList(HashMap unSortedMap)

Description

This function creates a sorted list using the maps

License

Open Source License

Parameter

Parameter Description
unSortedMap a parameter

Declaration

public static LinkedList<Entry<Long, Double>> mapTosortedScoreList(HashMap<Long, Double> unSortedMap) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;

import java.util.LinkedList;

import java.util.Map.Entry;

public class Main {
    /** This function creates a sorted list using the maps
     * @param unSortedMap/* w  w  w .ja v a  2s .  c  om*/
     * @return
     */
    public static LinkedList<Entry<Long, Double>> mapTosortedScoreList(HashMap<Long, Double> unSortedMap) {

        LinkedList<Entry<Long, Double>> mapList = new LinkedList<Entry<Long, Double>>(unSortedMap.entrySet());
        Collections.sort(mapList, new Comparator<Entry<Long, Double>>() {

            @Override
            public int compare(Entry<Long, Double> o1, Entry<Long, Double> o2) {
                // TODO Auto-generated method stub
                return o2.getValue().compareTo(o1.getValue());
            }

        });

        return mapList;

    }
}

Related

  1. isSorted(List list)
  2. isSortedDescending(List list)
  3. isStringListSortedDesc(List list)
  4. isUnsortedEventsMatch(List actual, List expected)
  5. ListToSortedArray(List list)
  6. maximum(List sortedDataAscendingOrder)
  7. mergeLong(List l1, List l2, boolean sort)
  8. mergeSort(List m)
  9. mergeSort(List list)