I have the following method to sort a% String of Hours String:
public static void ordenaHoras() {
ArrayList<String> horasList = new ArrayList<String>();
horasList.add("23:45");
horasList.add("11:13");
horasList.add("15:33");
horasList.add("12:27");
horasList.add("15:24");
Collections.sort(horasList, new Comparator<String>() {
private SimpleDateFormat sdf = new SimpleDateFormat("hh:mm");
@Override
public int compare(String o1, String o2) {
int result = -1;
try {
result = sdf.parse(o1).compareTo(sdf.parse(o2));
} catch (ParseException ex) {
ex.printStackTrace();
}
return result;
}
});
for (String hora: horasList) {
System.out.println(hora);
}
}
My problem is that the values of hours that start at number 12 are always wrong in the first place !!! The output of the above method execution is:
12:27
11:13
15:24
15:33
23:45