hyljava

          對數(shù)數(shù)組中的內(nèi)容強排序

          對數(shù)數(shù)組中的內(nèi)容強排序
          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 何云隆 閱讀(889) 評論(0)  編輯  收藏 所屬分類: java

          主站蜘蛛池模板: 德钦县| 宜良县| 兰坪| 永福县| 平谷区| 枞阳县| 饶平县| 炉霍县| 荆门市| 章丘市| 榆社县| 和静县| 阳西县| 曲阜市| 顺昌县| 奈曼旗| 弥勒县| 东海县| 吴旗县| 宜黄县| 满城县| 昂仁县| 怀柔区| 朝阳县| 陆川县| 同心县| 浦东新区| 施甸县| 伊金霍洛旗| 宿松县| 武城县| 南丹县| 修文县| 河池市| 株洲县| 沾化县| 东阳市| 临漳县| 澜沧| 东安县| 绥中县|