Below code is giving result two times but it should be one result.
import java.io.*; import java.util.*; public class DateAfterArrayTest { public boolean[] dateAfterArrayTest(Date[] dtArrVl1) { int cnt = 1; for (int i=0; i<dtArrVl1.length; i++) { System.out.println("Date value " + cnt + " is :" + dtArrVl1[i]); cnt ++; } System.out.println(); boolean[] rslt = new boolean[dtArrVl1.length]; for (int j=0; j<rslt.length; j++) { if (j != rslt.length-1) { rslt[j] = dtArrVl1[j].before(dtArrVl1[j+1]); } } return rslt; } public static void main(String[] args) { Date[] dtArr1 = {new Date(2017, 01, 15), new Date(2018, 01, 15)}; DateAfterArrayTest dateAfterArrInstnc = new DateAfterArrayTest(); boolean[] rsltVl = dateAfterArrInstnc.dateAfterArrayTest(dtArr1); System.out.println("Comparing date 1 value with date 2 :"); for(boolean fnlRslt : rsltVl) { System.out.println("Date after value is : " + fnlRslt); } } } ------------------------------- Output: Date value 1 is :Thu Feb 15 00:00:00 UTC 3917 Date value 2 is :Fri Feb 15 00:00:00 UTC 3918 Comparing date 1 value with date 2 : Date after value is : true Date after value is : false The last line of output should not come because in for loop if condition will fail at second interation. But in the retuning boolean value i'm having two results. Can anyone clarify this issue.