자바 vector에 있는 데이터를 내림차순이나 오름차순으로 정리하기
조회수 1895회
import java.util.Scanner;
public class Score {
public int id;
public String name;
public int score;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public void read(Scanner scanner) {
int id = scanner.nextInt();
this.setId(id);
String name = scanner.next();
this.setName(name);
int score = scanner.nextInt();
this.setScore(score);
}
public void Print() {
System.out.println(this.getId() + " " + this.getName() + " " + this.getScore());
}
}
private void sort() {
Score score = new Score();
Vector<Score> vector = new Vector<Score>();
try {
File file = new File("data/score.txt");
Scanner scanner = new Scanner(file);
while (scanner.hasNext()) {
score.read(scanner);
vector.add(score);
}
scanner.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
for (int i = 0; i < vector.size(); i++) {
vector.get(i).Print();
}
}
이렇게 텍스트 파일을 읽어와서 벡터에 집어넣는것 까지는 했는데욥 들어가 있는 데이터를 내림차순이나 오름차순으로 정리하기 위해서는 어떻게 해야 할까요?
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력