I'm writing a tiny java application that will read a person's details from a txt file(tab delimited)(id, First Name, Last Name, DoB, Address)
The txt file is already sorted by id and contains around 30,000 records. My program should provide the user the choice to sort either by First Name, Last Name or Address.
What i've done already is that I made a class Person and made an arraylist of type Person to store all the records and then used JAVA's collection sort to sort it by using different comparators like this:
public static Comparator<Person> addComp = new Comparator<Person>(){
public int compare(Person P1,Person P2){
String add1 = P1.getadd().toUpperCase();
String add2 = P2.getadd().toUpperCase();
return add1.compareTo(add2);
}
};
It works and all but what I wanted to know was if there was a faster algorithm to do it like in terms of running time and complexity.
Like if there was any other data structure that would be more suitable like a hash table or something