在项目中,我看到一个人误创建的多个区域存储桶,该存储桶用于数据管道。应该是区域性的桶。建议将其更改为区域存储桶的建议方法是什么?
答案 0 :(得分:2)
您可以尝试执行以下命令
import java.io.*;
import java.util.*;
public class Grades {
private static ArrayList<Student> sort(ArrayList<String> list) {
ArrayList<Student> students = new ArrayList<Student>();
String name = "";
int grade;
for (String line : list) {
String[] splitted = line.split("\\s+");
for(int i = 0;i< splitted.length-1;i++){
name += splitted[i] + " ";
}
grade = Integer.parseInt(splitted[splitted.length-1]);
students.add(new Student(name,grade));
name = "";
}
students.sort(Comparator.comparing(student-> student.getGrade()));
return students;
}
public static void main(String[] args){
ArrayList<String> list = new ArrayList<>();
String fileName = "students.txt";
try (BufferedReader input = new BufferedReader(new FileReader(fileName))) {
while(input.ready()){
list.add(input.readLine());
}
input.close();
ArrayList<Student> sortedStudents = sort(list);
for (Student currentStudent : sortedStudents)
System.out.println(currentStudent.getName() + currentStudent.getGrade());
} catch (IOException e){
System.out.println(e.getMessage());
}
}
}