Java HashMap Sort getSortedColors(HashMap colors)

Here you can find the source of getSortedColors(HashMap colors)

Description

get Sorted Colors

License

Open Source License

Declaration

public static Collection<Entry<Integer, Integer>> getSortedColors(HashMap<Integer, Integer> colors) 

Method Source Code

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

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map.Entry;

public class Main {
    public static Collection<Entry<Integer, Integer>> getSortedColors(HashMap<Integer, Integer> colors) {
        ArrayList<Entry<Integer, Integer>> colorList = new ArrayList<>(colors.entrySet());
        Collections.sort(colorList, new Comparator<Entry<Integer, Integer>>() {
            @Override//ww w .  ja va2 s  .co m
            public int compare(final Entry<Integer, Integer> o1, final Entry<Integer, Integer> o2) {
                return -o1.getValue() + o2.getValue();
            }
        });
        return colorList;
    }
}

Related

  1. getSortedHashMapKeyset(Map sorting)
  2. getSortedLinkedHashMap(Map bitCounts, Comparator comparator)
  3. sortByComparator(HashMap unsortMap, final boolean ascendingorder)
  4. sortByValue(HashMap map)

  5. HOME | Copyright © www.java2s.com 2016