package test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public
class Test {
public static void main(String[] args) {
List<People> list = new ArrayList<People>();
People people1 = new People();
people1.setName("cep_20121212080912");
people1.setAge(12);
People people2 = new People();
people2.setName("cep_20131212081912");
people2.setAge(8);
People people3 = new People();
people3.setName("cep_20121212081112");
people3.setAge(45);
list.add(people1);
list.add(people2);
list.add(people3);
Collections.sort(list, new Comparator<People>() {
@Override
public int compare(People o1, People o2) {
// TODO Auto-generated method stub
return o1.getName().compareTo(o2.getName());
}
});
for(People p : list){
System.out.println(p.getName() +" " +p.getAge());
}
}
}
class People{
public String name;
public int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}