list集合根据对象的某个字段排序 ArrayList<UsersBean> usersBeans = new ArrayList<UsersBean>(); UsersBean usersBean1 = new UsersBean("1", "a", "a"); UsersBean usersBean2 = new UsersBean("1", "d", "a"); UsersBean usersBean3 = new UsersBean("2", "b", "a"); UsersBean usersBean4 = new UsersBean("3", "c", "a"); usersBeans.add(usersBean1); usersBeans.add(usersBean2); usersBeans.add(usersBean3); usersBeans.add(usersBean4); Collections.sort(usersBeans, new Comparator<UsersBean>() { @Override public int compare(UsersBean o1, UsersBean o2) { int o1id = Integer.parseInt(o1.getId()); int o2id = Integer.parseInt(o2.getId()); // 按照id进行升序排列 if (o1id > o2id) { return 1; } if (o1id == o2id) { return 0; } return -1; } }); usersBeans.forEach(v->{ System.out.println(v); });