//根据List集合中某个对象中的元素对集合进行排序

//根据List集合中某个对象中的元素对集合进行排序
//排序字段为String时


  1. java.util.Collections.sort(list,new Comparator<Bean>() {
  2. @Override
  3. public int compare(Bean arg0, Bean arg1) {
  4. return arg0.getBillNo().compareTo(arg1.getBillNo());
  5. }
  6. });

//排序字段为int时

  1. java.util.Collections.sort(glManifestIHeadList,new Comparator<GlManifestIHead>() {
  2. @Override
  3. public int compare(GlManifestIHead arg0, GlManifestIHead arg1) {
  4. if(arg0.getBillNo()>arg1.getBillNo()){
  5. return 1;
  6. }
  7. if(arg0.getBillNo()<arg1.getBillNo()){
  8. return -1;
  9. }
  10. return 0;
  11. };

//排序单纯String

  1. String mealTypeId = req.getParameter("mealTypeId");//餐别 "0,3,5,1,2,4"
  2. String [] meals = mealTypeId.split(",");
  3. List<String> list = Arrays.asList(meals);
  4. Collections.sort(list, String::compareTo);
  5. mealTypeId = String.join(",", list);//"0,1,2,3,4,5"

、、
}