Sắp xếp arrlist theo thứ tự từ điển - Java

  • chuyện thế này các bác ạ:
  • em có 1 arrlist chứa kiểu dữ liệu là 1 class student, em muốn sắp xếp tên theo từ diển mà không được các bác giúp em với nó báo lỗi.
public static void sortedStudent(ArrayList<studentCollege> liStudentColleges) {

		Collections.sort(liStudentColleges, new Comparator<String>() {
			@Override
			public int compare(String s1, String s2) {
				
				return s1.compareToIgnoreCase(s2);
  • các bác giúp em với em cám ơn!

List student thì Conparator< Student> mới dc

1 Like

em thử rồi k đc bác ạ
em sủa thành thế này đc k bác:
public static void sortedStudent(ArrayList liStudentColleges) {

	Collections.sort(liStudentColleges, new Comparator<studentCollege>() {
		@Override
		public int compare(studentCollege o1, studentCollege o2) {
			// TODO Auto-generated method stub
			return o1.getName().compareToIgnoreCase(o2.getName());

			
		}
	});
}
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?