fork 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. NavigableMap < String, Integer > map =
  13. new TreeMap<>(
  14. .comparing( ( String s ) -> s.codePoints().count() )
  15. .thenComparing( String :: compareTo )
  16. );
  17. map.putAll(
  18. Map.of (
  19. "abc", 1 ,
  20. "x", 2 ,
  21. "b" , 3 ,
  22. "a" , 4 ,
  23. "yz", 5
  24. )
  25. ) ;
  26. System.out.println( map ) ;
  27. }
  28. }
Success #stdin #stdout 0.1s 48748KB
stdin
Standard input is empty
stdout
{a=4, b=3, x=2, yz=5, abc=1}