Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.ArrayList;

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

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class Main {
    public static <T extends Comparable> List<Entry<String, T>> sortMapDesc(Map<String, T> keywordMap) {
        List<Entry<String, T>> arrayList = new ArrayList<Entry<String, T>>(keywordMap.entrySet());
        Collections.sort(arrayList, new Comparator<Entry<String, T>>() {

            @Override
            public int compare(Entry<String, T> e1, Entry<String, T> e2) {
                return (e2.getValue()).compareTo(e1.getValue());
            }
        });
        return arrayList;
    }
}