fork(7) 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.format.* ;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. String input = "coming from the 11/25/2009 to the 11/30/2009" ;
  16. String[] elements = input.split( " " ) ;
  17. DateTimeFormatter f = DateTimeFormatter.ofPattern( "MM/dd/uuuu" ) ;
  18. List<LocalDate> dates = new ArrayList<>() ;
  19. for( String element : elements ) {
  20. try {
  21. LocalDate ld = LocalDate.parse( element , f ) ;
  22. dates.add( ld ) ;
  23. } catch ( DateTimeParseException e ) {
  24. // Ignore the exception. Move on to next element.
  25. }
  26. }
  27. System.out.println( "dates: " + dates ) ;
  28.  
  29. }
  30. }
Success #stdin #stdout 0.14s 4386816KB
stdin
Standard input is empty
stdout
dates: [2009-11-25, 2009-11-30]