| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + package com.hmkcode; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | + import java.util.HashMap; | ||
| 5 | + import java.util.Map; | ||
| 6 | + | ||
| 7 | + public class Test { | ||
| 8 | + public static void main(String[] args){ | ||
| 9 | + | ||
| 10 | + | ||
| 11 | + Map map = new HashMap(); | ||
| 12 | + | ||
| 13 | + //*value Class should implements the Comparable interface | ||
| 14 | + //*String implements Comparable by default. | ||
| 15 | + | ||
| 16 | + map.put("Z", "3"); | ||
| 17 | + map.put("D", "4"); | ||
| 18 | + map.put("A", "1"); | ||
| 19 | + map.put("B", "2"); | ||
| 20 | + map.put("F", "6"); | ||
| 21 | + map.put("E", "5"); | ||
| 22 | + | ||
| 23 | + System.out.println("Unsorted Map: "+map); | ||
| 24 | + System.out.println("Sorted Map By Values: "+MapSort.sortByValue(map)); | ||
| 25 | + System.out.println("Sorted Map By Keys: "+MapSort.sortByKey(map)); | ||
| 26 | + | ||
| 27 | + } | ||
| 28 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments