Java 如何根据GPA按升序对数组列表进行排序?arraylist包含一个对象数组。(爪哇)
我试图根据GPA按升序对这个arraylist进行排序。学生班级封装了3条信息:学生编号、姓氏、平均分数 所以我需要使用gradePointAverage对它们进行排序Java 如何根据GPA按升序对数组列表进行排序?arraylist包含一个对象数组。(爪哇),java,arrays,sorting,arraylist,Java,Arrays,Sorting,Arraylist,我试图根据GPA按升序对这个arraylist进行排序。学生班级封装了3条信息:学生编号、姓氏、平均分数 所以我需要使用gradePointAverage对它们进行排序 //student array studentArray[0] = student; studentArray[1] = new Student(9093891, "Brown", 2.55); studentArray[2] = new Student(9301879, "Carson", 1.11); studentArra
//student array
studentArray[0] = student;
studentArray[1] = new Student(9093891, "Brown", 2.55);
studentArray[2] = new Student(9301879, "Carson", 1.11);
studentArray[3] = new Student(3910880, "Deardon", 4.01);
studentArray[4] = new Student(8891783, "Ellis", 2.66);
studentArray[5] = new Student(3899132, "Fisher", 0.55);
//filling my studentlist
studentList.add(student);
studentList.add(studentArray[0]);
studentList.add(studentArray[1]);
studentList.add(studentArray[2]);
studentList.add(studentArray[3]);
studentList.add(studentArray[4]);
ArrayList<String> sortedArrayListDescending = studentList.sortDescending();
//学生数组
学生阵列[0]=学生;
学生阵列[1]=新生(9093891,“布朗”,2.55);
学生阵列[2]=新生(9301879,“卡森”,1.11);
studentArray[3]=新生(3910880,“迪尔登”,4.01);
studentArray[4]=新生(8891783,“Ellis”,2.66);
studentArray[5]=新生(3899132,“Fisher”,0.55);
//填写我的学生名单
学生列表。添加(学生);
studentList.add(studentArray[0]);
添加(studentArray[1]);
添加(studentArray[2]);
添加(studentArray[3]);
添加(studentArray[4]);
ArrayList SortDarrayListDescending=studentList.sortDescending();
使用Collections.sort()
升序
Collections.sort(studentList,Comparator.comparingDouble(Student::getGradePointsAverage));
Collections.sort(list,Comparator.comparingDouble(Student::getGradePointsAverage).reversed());
降序
Collections.sort(studentList,Comparator.comparingDouble(Student::getGradePointsAverage));
Collections.sort(list,Comparator.comparingDouble(Student::getGradePointsAverage).reversed());
我知道上面写着studentList.sortdescenting(),但即使这样也不行。那是胡闹。我得到一个“错误:找不到符号”我得到一个“错误:找不到符号”,这是因为列表中没有
sortDescending
或sortAscending
方法,有sort
方法,该方法使用Comparator
表示用于首先检查两个比较对象是否相等的机制,比第二个大或小。