fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Map < String, Integer > otherMap =
  13. Map.of(
  14. "Alice" , 2 ,
  15. "Bob" , 3 ,
  16. "Carol" , 2
  17. );
  18.  
  19. NavigableMap < String, Integer > navMap = new TreeMap <>( Comparator.comparingInt( otherMap :: get ) );
  20.  
  21. navMap.put( "Alice" , 100 );
  22. navMap.put( "Bob" , 200 );
  23. navMap.put( "Carol" , 300 );
  24.  
  25. System.out.println( "otherMap = " + otherMap );
  26. System.out.println( "navMap = " + navMap );
  27. }
  28. }
Success #stdin #stdout 0.13s 50492KB
stdin
Standard input is empty
stdout
otherMap = {Bob=3, Carol=2, Alice=2}
navMap = {Alice=300, Bob=200}