Hi all I want to sort 2 related files, creating an unique index which can sort both of them
I have a .txt file formatted as the following sample:
File1
Houston
Chicago
Seattle
Cleveland
The other file is formatted like this:
File2
44
33
55
22
I want the following output:
Seattle 55
Houston 44
Chicago 33
Cleveland 22
I've created 2 array of objects from the .txt files, so I can't use bubblesort because of the "< or >" operator. I've used .sort function to sort the scores but in this way I don't create an index to sort the teams. How can I solve the problem?
That's my code
private void visualizzaClassificaButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
List<String> teams = new ArrayList<String>();
List<Float> scores = new ArrayList<Float>();
try {
FileInputStream fstream = new FileInputStream("C:/Users/Fra....../file1");
FileInputStream fstream2 = new FileInputStream("C:/Users/Fra...../file2");
DataInputStream in = new DataInputStream(fstream);
DataInputStream in2 = new DataInputStream(fstream2);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
BufferedReader br2 = new BufferedReader(new InputStreamReader(in2));
String team = null;
String score = null;
while ((score = br.readLine()) != null && (team = br2.readLine()) !=null) {
teams.add(team);
scores.add(Float.parseFloat(score));
}
Object[] squadreTutte = teams.toArray();
Object[] punteggiTutti = scores.toArray();
Arrays.sort(punteggiTutti, Collections.reverseOrder());
//????????????????????????????????
for(int index=0; index<punteggiTutti.length; index++){
System.out.println(punteggiTutti[index]);
System.out.println(squadreTutte[index]);
}
in.close();
} catch (Exception e) {
}
}
Please help