Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

public class Main {
    public static void main(String[] args) {
        Map<Integer, String> map = new TreeMap<Integer, String>(new MyComparator());

        map.put(2, "v");
        map.put(3, "h");
        map.put(4, "e");
        map.put(1, "a");

        System.out.println(map);
    }

}

class MyComparator implements Comparator<Integer> {

    @Override
    public int compare(Integer first, Integer second) {

        return second.compareTo(first);
    }
}