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. import java.math.*;
  8. import java.util.*;
  9. import java.util.function.Function;
  10. import java.util.stream.*;
  11.  
  12.  
  13. /* Name of the class has to be "Main" only if the class is public. */
  14. class Ideone
  15. {
  16. public static void main (String[] args) throws java.lang.Exception
  17. {
  18. List < String > list = List.of( "200.1043725170" , "100.1043725171" , "100.1043725170" , "65535.4294967295" , "4294967295.65535" );
  19. NavigableMap < BigDecimal, String > map =
  20. list
  21. .stream()
  22. .collect(
  23. Collectors.toMap(
  24. ( String s ) -> new BigDecimal( s ) ,
  25. Function.identity() ,
  26. ( existing , replacement ) -> existing , // In case of duplicate key conflict, first one wins.
  27. TreeMap :: new
  28. )
  29. );
  30. List < String > result = List.copyOf( map.values() );
  31.  
  32. System.out.println( result );
  33. }
  34. }
Success #stdin #stdout 0.08s 48984KB
stdin
Standard input is empty
stdout
[100.1043725170, 100.1043725171, 200.1043725170, 65535.4294967295, 4294967295.65535]