主要利用了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()); }