I am trying to execute following code and found that for loop is not executing at all. Even not getting any error. Let me clear that "dateList" is a list of string and it's not empty, I already tried printing that. "monthList" is an ArrayList of string.
private ArrayList<String> monthList = new ArrayList<String>(Arrays.asList("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"));
private List<String> dateList = new ArrayList<>();
private List<Date> finalDatesInMMMDDYYYYFormate = new ArrayList<>();
private int year = 2019;
for (int m=0; m<dateList.size(); m++){
System.out.println("Date at position ------ "+m+" is -------"+dateList.get(m));
} // length of this list is 9 & it prints eberything from 0 to 9. It is not empty.
int assignYear = year;
for (int k=1; k<dateList.size(); k++){
if (dateList.get(k).substring(0,2)==dateList.get(k-1).substring(0,2) || dateList.get(k).substring(0,2) == monthList.get(0)){
finalDatesInMMMDDYYYYFormate.add(Utils.parseDate(dateList.get(k)+Integer.toString(assignYear).replaceAll("[^a-zA-Z0-9]",""), new SimpleDateFormat("MMMddyyyy")));
}
else if (dateList.get(k).substring(0,2) == monthList.get(11)){
finalDatesInMMMDDYYYYFormate.add(Utils.parseDate(dateList.get(k)+Integer.toString(assignYear-1).replaceAll("[^a-zA-Z0-9]",""), new SimpleDateFormat("MMMddyyyy")));
assignYear = assignYear-1;
}
else {
for (int l=0; l<monthList.indexOf(dateList.get(k-1).substring(0,2)); l++){
if (dateList.get(k).substring(0,2) == monthList.get(l)){
finalDatesInMMMDDYYYYFormate.add(Utils.parseDate(dateList.get(k)+Integer.toString(assignYear).replaceAll("[^a-zA-Z0-9]",""), new SimpleDateFormat("MMMddyyyy")));
break;
}
else {
finalDatesInMMMDDYYYYFormate.add(Utils.parseDate(dateList.get(k)+Integer.toString(assignYear-1).replaceAll("[^a-zA-Z0-9]",""), new SimpleDateFormat("MMMddyyyy")));
assignYear--;
break;
}
}
}
}