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.time.* ;
  8. import java.time.temporal.* ;
  9. import java.time.format.* ;
  10.  
  11. /* Name of the class has to be "Main" only if the class is public. */
  12. class Ideone
  13. {
  14. public static void main (String[] args) throws java.lang.Exception
  15. {
  16.  
  17. List< MonthDay > mds = new ArrayList<>() ;
  18. mds.add( MonthDay.of( 7 , 22 ) ) ;
  19. mds.add( MonthDay.of( Month.AUGUST , 25 ) ) ;
  20. mds.add( MonthDay.of( Month.JUNE , 25 ) ) ;
  21. mds.add( MonthDay.of( Month.SEPTEMBER , 28 ) ) ;
  22. mds.add( MonthDay.of( 9 , 5 ) ) ;
  23. Collections.sort( mds ) ;
  24.  
  25. DateTimeFormatter f = DateTimeFormatter.ofPattern( "dd/MM" ) ;
  26. String output = mds.get( 0 ).format( f ) ; // Generate string in custom format.
  27.  
  28. System.out.println( "mds: " + mds ) ;
  29. System.out.println( "mds.get( 0 ) = " + mds.get( 0 ) + " | output: " + output ) ;
  30. }
  31. }
Success #stdin #stdout 0.15s 2184192KB
stdin
Standard input is empty
stdout
mds: [--06-25, --07-22, --08-25, --09-05, --09-28]
mds.get( 0 ) = --06-25  |  output: 25/06