hyljava

          對數數組中的內容強排序

          對數數組中的內容強排序
          import java.util.ArrayList;
          import java.util.Collections;
          import java.util.Comparator;
          public class TestComparator {
            public static void main(String[] args){
                   ArrayList list = new ArrayList();
                   list.add(new Persion("lcl",28));
                   list.add(new Persion("fx",23));
                   list.add(new Persion("wqx",29));
                   Comparator comp = new Comparator(){
                    public int compare(Object o1,Object o2) {
                        Persion p1=(Persion)o1;
                        Persion p2=(Persion)o2;
                       if(p1.age<p2.age)
                           return 1;
                       else
                           return 0;
                       }
                  };
           
                  Collections.sort(list,comp);
                 
                  for(int i=0;i<list.size();i++){
                   Persion p=(Persion) list.get(i);
                   System.out.println(p.age+"+"+p.name);
                   }
            }

          }

          posted on 2012-07-20 09:42 何云隆 閱讀(891) 評論(0)  編輯  收藏 所屬分類: java

          主站蜘蛛池模板: 色达县| 米脂县| 精河县| 易门县| 台北县| 扶绥县| 安阳县| 海伦市| 安西县| 南康市| 达日县| 淮北市| 大姚县| 新平| 会昌县| 芒康县| 高淳县| 沈阳市| 祁东县| 南漳县| 普宁市| 全南县| 辽阳市| 丽江市| 龙陵县| 信阳市| 张家港市| 全南县| 盈江县| 彰武县| 修文县| 呼图壁县| 龙海市| 和顺县| 沙坪坝区| 二手房| 抚顺市| 石狮市| 毕节市| 康马县| 蒙自县|