/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.time.*;
import java.time.temporal.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
List<String> inputs = new ArrayList<> ();
inputs.add ( "2016-01-23" );
inputs.add ( "2016-01-25" );
inputs.add ( "2016-02-22" ); // End of longest period between dates.
inputs.add ( "2016-02-25" );
inputs.add ( "2016-02-28" );
LocalDate longestStart = null;
LocalDate longestStop = null;
LocalDate previousDate = null;
long longestInDays = 0;
for ( String input
: inputs
) { LocalDate currentDate = LocalDate.parse ( input );
if ( null == previousDate ) { // First loop.
previousDate = currentDate;
continue; // Skip the rest of this first loop.
}
long currentDays = ChronoUnit.DAYS.between ( previousDate , currentDate );
if ( currentDays > longestInDays ) {
// If the current loop exceeds previous longest, remember this one as longest.
longestInDays = currentDays;
longestStart = previousDate;
longestStop = currentDate;
}
// Prepare for next loop.
previousDate = currentDate;
}
System.
out.
println ( "Longest period has days: " + longestInDays
+ " = " + longestStart
+ "/" + longestStop
);
}
}