我又该走向何方
TestComparator.javapackage com.fangq.collections;
import java.util.Arrays;
import org.apache.commons.lang.math.RandomUtils;/** * * @author fangq */public class TestComparator { public static void main(String[] args){ StudentDTO[] dtos = new StudentDTO[10]; for(int i=0;i<dtos.length;i++){ dtos[i] = new StudentDTO(); dtos[i].setXh("xh"+i); dtos[i].setXm("xm"+i); dtos[i].setNl(String.valueOf(i+RandomUtils.nextInt(20))); } System.out.println("排序前==============="); for(int j=0;j<dtos.length;j++) System.out.println("姓名:"+dtos[j].getXm()+"年龄:"+dtos[j].getNl()); Arrays.sort(dtos,new StudentComparator()); System.out.println("排序后==============="); for(int k=0;k<dtos.length;k++) System.out.println("姓名:"+dtos[k].getXm()+"年龄:"+dtos[k].getNl()); }}
Powered by: BlogJava Copyright © hama