fork(3) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.stream.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. Map<String,Integer> map = new HashMap<String,Integer>();
  14. map.put("eggs",1500);
  15. map.put("echo",150);
  16. map.put("foo",320);
  17. map.put("smt",50);
  18.  
  19.  
  20. List<String> word_used = new ArrayList<String>(
  21. map
  22. .entrySet()
  23. .stream()
  24. .sorted((o1, o2) -> (o2.getValue()).compareTo( o1.getValue()))
  25. .map(Map.Entry<String,Integer>::getKey)
  26. .collect(Collectors.toList())
  27. );
  28. List<Integer> ints_used = new ArrayList<Integer>(
  29. map
  30. .entrySet()
  31. .stream()
  32. .sorted((o1, o2) -> (o2.getValue()).compareTo( o1.getValue()))
  33. .map(Map.Entry<String,Integer>::getValue)
  34. .collect(Collectors.toList())
  35. );
  36.  
  37. for (String s : word_used) {
  38. System.out.println(s);
  39. }
  40. for (Integer i : ints_used) {
  41. System.out.println(i);
  42. }
  43. }
  44. }
Success #stdin #stdout 0.21s 320832KB
stdin
Standard input is empty
stdout
eggs
foo
echo
smt
1500
320
150
50