contains method is used to determine whether the specified element is included in the list. Returns true if the specified element is contained in the list, false otherwise.
Syntax:
contains(Object o);
o: To determine whether an element exists in the list.
Specific usage examples: traverse list data and filter out data with the same time
try { List list = new ArrayList(); List equipmentLocationList = locationService.getUserTrajectoryList(); List list2 = new ArrayList(); for (Location location : equipmentLocationList) { // 过滤时间相同的数据 if (list2.contains(location.getDeviceTime().getTime())) { continue; } EcgUser user = new EcgUser(); user.setLatitude(location.getLatitude()); user.setLongitude(location.getLongitude()); list.add(user); list2.add(location.getDeviceTime().getTime()); } System.out.println(list2); return getResponse(list); } catch (Exception e) { logger.error("", e); return getResponse(ErrorCodeConstant.FAIL.getCode()); }
Recommended tutorial: Java tutorial
The above is the detailed content of Java determines whether list contains a certain value. For more information, please follow other related articles on the PHP Chinese website!