siehe hier: Insel
Ansonsten wie hast du die Daten gespeichert? Als String? Date? eigene Klasse?
String[] strings = {"12.3.91", "20.1.92", "14.12.91"};
DateFormat df = DateFormat.getDateInstance();
try {
Date[] dates = new Date[strings.length];
for(int i = 0; i < strings.length; i++) {
dates[i] = df.parse(strings[i]);
}
Arrays.sort(dates);
System.out.println("Sorted Array: " + Arrays.toString(dates));
} catch (ParseException e) {
e.printStackTrace();
}
Ok nach dem Einlesen der Datei liegen die Daten also als String vor. Das einfachste dürfte dann sein die Strings in Dates umzuwandeln - dafür gibt es die Klasse DateFormat:
mal ein kleines Beispiel...
public class BirthdayDate implements Comparable<BirthdayDate> {
private int day;
private int month;
private int year;
public BirthdayDate(String s) {
String[] values = s.split("\\.");
if (values.length != 3) {
throw new IllegalArgumentException("This is not a valid date");
}
day = Integer.valueOf(values[0]);
month = Integer.valueOf(values[1]);
year = Integer.valueOf(values[2]);
}
public int getDay() {
return day;
}
@Override
public String toString() {
return day + "." + month + "." + year;
}
public int getMonth() {
return month;
}
public int getYear() {
return year;
}
public int getAge() {
return 0;
}
@Override
public int compareTo(BirthdayDate o) {
if (month == o.getMonth() && day == o.getDay()) {
return 0;
}
if (month > o.getMonth()) {
return 1;
}
if (day > o.getDay()) {
return 1;
}
return -1;
}
}