List<Users> list = new ArrayList<Users>();
list.add(new Users("张三",442));
list.add(new Users("里斯",4544));
list.add(new Users("王五",244));
list.add(new Users("赵六",344));
list.add(new Users("夏吧",444));
list.add(new Users("初五",434));
list.add(new Users("一号",144));
请根据资金的大小进行一次排序! 

解决方案 »

  1.   

    可以先把list转化为数组,然后通过Arrays.sort()排序,可以看文档,令外person对象要实现compareBle接口,实现的compareTo方法里面用资金比较。
      

  2.   

    Collections.sort(list, new  Comparator {
    int compare(Users o1, Users o2) {
    return o1.编号 - o2.编号
    }});
    编号就是442的字段名
      

  3.   

    public class ComparatorUser implements Comparator<Users>{ @Override
    public int compare(Users user0, Users user1) {
     user0.getAge().compareTo(user1.getAge());             
    return 0;
    }
     }
     红色部分编译的时候出错:Cannot inVoke compare(int) on the primitive type int
      

  4.   

         Map map = new HashMap();     List<Users> list = new ArrayList<Users>();
         list.add(new Users("张三",442));
         list.add(new Users("里斯",4544));
         list.add(new Users("王五",244));
         list.add(new Users("赵六",344));
         list.add(new Users("夏吧",444));
         list.add(new Users("初五",434));
         list.add(new Users("一号",144));     Set set = map.entrySet();
            for(Iterator i = set.iterator();i.hasNext();)
            {
                Map.Entry entry = (Map.Entry)i.next();
                list.add(entry);
            }
            
            Collections.sort(list,new Comparator()
            {
                public int compare(Object o1, Object o2) {
                    Map.Entry e1 = (Map.Entry)o1;
                    Map.Entry e2 = (Map.Entry)o2;
                    return Integer.parseInt(e1.getValue().toString())-Integer.parseInt(e2.getValue().toString());
                }
            });        list.reverse();         System.out.print("根据资金的大小:");
             for(Iterator i = list.iterator();i.hasNext();)
            {         
                Map.Entry entry = (Map.Entry)i.next();
                System.out.print(entry.getKey()+":"+entry.getValue()+", ");
            }
             
      

  5.   

    看不懂。都出错了!我在eclipse中试了 编译就出错了!  list.reverse();
      

  6.   

    如2楼。。 
     实现compareable接口就可以了...
      将排序目标指向资金...
      

  7.   

    测试类方法:
    List<Users> list = new ArrayList<Users>();
     list.add(new Users("张三",442));
     list.add(new Users("里斯",4544));
     list.add(new Users("王五",244));
     list.add(new Users("赵六",344));
     list.add(new Users("夏吧",444));
     list.add(new Users("初五",434));
     list.add(new Users("一号",144));
     Collections.sort(list, new Comparator<Users>() {
    public int compare(Users o1, Users o2) {
    return o1.getAge() - o2.getAge();
    } }); for (Users u : list) {
    System.out.println(u.getAge());
    }
    Users类:
    public class Users implements Comparable<Users> {
    private String name;
    private int age;


    public Users(String name, int age) {
    super();
    this.name = name;
    this.age = 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;
    }
    @Override
    public int compareTo(Users u1) {
    if(this.age > u1.getAge())
    return 0;
    else return 1;
    }

    }
      

  8.   

    public static void main(String[] args) {
        java.util.Set<User> set = new java.util.TreeSet<User>(
            new java.util.Comparator() {
                public int compare(Object o1, Object o2) {
                    Integer p1 = ((Users)o1).getAge();
                    Integer p2 = ((Users)o2).getAge();
                    return p1 > p2 ? 1 : (p1 == p2 ? 0 : -1);
                }
            }
        );
        set.add(new Users("name1", 30));
        set.add(new Users("name2", 40));
        set.add(new Users("name3", 20));
        set.add(new Users("name4", 80));
        for (Users user : set) {
            System.out.println(user.getName());
        }
    }