java - alphabetical order (list) [duplicate]
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Sort List Alphabetically how do i store my inputs in alphabetical order, i am inputting names into an arraylist: persons.add(person); How to do that? 回答1: Try this: java.util.Collections.sort(people); 回答2: implements Comparator< T > interface class A implements Comparator < Person > { @Override public int compare(Person o1, Person o2) { if(o1.getName() != null && o2.getName() != null){ return o1.getName()