I read a file where every line looks like this:
userName,age,award
I need to program two sorting types : by userName and by age. I had no problem with first one, but I have no idea how to sort by age in such example..
I tried switching name with age in each line but it doesn't work.
That's what I have ( it's basically only reading from a file and displaying it ):
try{
File file=new File(path);
BufferedReader read=new BufferedReader(new FileReader(file));
String line=read.readLine();
all+=line+"\n";
while(line!=null){
line=save.readLine();
all+=line+"\n";
}
String [] tabUsers=all.split("\n");
String display="";
for(int a=0;a<tabUsers.length-1;a++){
display+=tabUsers[a]+"\n";
}
for(int c=0;c<tabUsers.length-1;c++){
System.out.println(tabUsers[c]);
}
}
catch(Exception ex){
}
Any ideas?
I have tried this, but it did not work :
for(int b=0;b<tabUsers.length-1;b++){
String eachLine =tabUsers[b];
String [] splitLine=eachLine.split(",");
splitLine[0]=splitLine[1];
}
Stringor just by natural order relation onint...? Can you show what you are doing for names?