Java - can't find character (array sort collection)

Hi, I ran into a problem while sorting an arrayList as shown below (and yes, I imported using):

    Collections.sort(personer);

I have this list:

private List<Person> personer;

public Register() {
    personer = new ArrayList<Person>();
}

But I got an error:

mittscript.java:45: cannot find symbol symbol: method sort (java.util.List) location: class java.util.Collections Collections.sort (personer);

+3
source share
3 answers

I answered you in another java post - alphabetically (list)

I believe that if you do, fix your problems.

Collection<Person> listPeople = new ArrayList<Person>();

Person.java class will implement Comparable

public class Person implements Comparable<Person>{

public int compareTo(Person person) {
  if(this.name != null && person.name != null){
   return this.name.compareToIgnoreCase(person.name);
  }
  return 0;
 }

}

Once you have this, in the class you add people, when you are done adding, type:

Collections.sort(listPeople);
+4

Collections sort. Person Comparable, sort.
JVM , Person "" "", .

. .

, 1

class Person implements Comparable {
    ...
}

Collections.sort(list);

2

Collections.sort(list, myCustomComparator);
+2

You have to implement Comparable < T > Interface

+2
source

Source: https://habr.com/ru/post/1781843/


All Articles