Ich bin neu mit Java und habe einige Probleme mit einer Aufgabe. Ich habe Datei txt, die wie folgt aussieht:Java, sortieren und Anzeigen von Daten aus TXT-Datei
John Doe,01-01-1980,Development,Senior Developer
Susan Smith,07-12-1983,Development,Head of Development
Ane Key,06-06-1989,BA,Junior Analyst
Nina Simone,21-09-1979,BA,Head of BA
Tom Popa,23-02-1982,Development,Developer
Tyrion Lannyster,17-03-1988,BA,Analyst
, und ich will es von Abteilungen zu sortieren. zum Beispiel: Mitglieder sind:
[Employee Full Name] - [Employee Age] - [Employee Position] - [Employee Salary(default value x)]
Deparment: Entwicklung Mitglieder sind: Susan Smith ...... John Doe ...... Tom Popa ...... Abteilung: BA Mitglieder sind: Nina Simone ....... Ane Key ........... Tyrion Lannyster ........
zunächst Datei lesen und machte 2d Array aber kann nicht fortfahren, wie man es richtig sortiert.
public static void main(String[] args) {
String csvFile = "C:\\Employees.txt";
BufferedReader br = null;
String line = "";
String SplitBy = ",";
String myArray[][] = new String[6][5];
int row = 0;
try {
br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine()) != null) {
String nums[] = line.split(SplitBy);
for (int col = 0; col < nums.length; col++){
String n =nums[col];
myArray[row][col] = n;
// System.out.println(n);
}
row++;
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Haben Sie über Tutorial oder Algorithm darüber gesucht? Dies sollte Ihnen helfen, Ihr Array zu sortieren. – AxelH