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. import java.util.stream.* ;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14.  
  15. List < String > inputs =
  16. new ArrayList <>(
  17. List.of(
  18. "Mark,10,0,34" ,
  19. "Tom,2,7,19" ,
  20. "Billy,2,0,7"
  21. )
  22. );
  23.  
  24. List < String > sorted =
  25. inputs
  26. .stream()
  27. .sorted( ( String s1 , String s2 ) -> Integer.valueOf( s1.split( "," )[ 3 ] ).compareTo( Integer.valueOf( s2.split( "," )[ 3 ] ) ) )
  28. .collect( Collectors.toList()) ; // In Java 16+: .toList();
  29.  
  30. System.out.println( "sorted = " + sorted );
  31.  
  32. }
  33. }
Success #stdin #stdout 0.17s 36692KB
stdin
Standard input is empty
stdout
sorted = [Billy,2,0,7, Tom,2,7,19, Mark,10,0,34]