자바 vector에 있는 데이터를 내림차순이나 오름차순으로 정리하기

조회수 1887회
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();
        }

    }

이렇게 텍스트 파일을 읽어와서 벡터에 집어넣는것 까지는 했는데욥 들어가 있는 데이터를 내림차순이나 오름차순으로 정리하기 위해서는 어떻게 해야 할까요?

  • (•́ ✖ •̀)
    알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)