Java中判断List中是否有重复元素

主要利用了set会去重。

List<String> mobileList = new ArrayList<String>();
  for (PiaoHouFrontBookInfoFormViewModel p : model.getBookInfoList()) {
   mobileList.add(p.getMobile());
  }
  Set<String> set=new HashSet<String>(mobileList);
  boolean  mobileresult= mobileList.size() == set.size() ? true : false;
  if(!mobileresult) {
   //说明有重复手机号
   return JsonResult.jsonWsReturn(Status.ERROR.getCode(), "所有乘客手机号不能重复!",
     Status.ERROR_MSG_BY_SELF.getCode());
  }

 

posted @ 2020-05-15 19:42  十月围城小童鞋  阅读(4888)  评论(0)    收藏  举报