contains方法用于判断列表中是否包含指定元素。如果列表中包含指定元素,则返回true,否则返回false。
语法:
contains(Object o);
o:要判断是否存在于列表中的元素。
具体使用举例:遍历list数据,过滤掉时间相同的数据
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()); }
推荐教程:Java教程
立即学习“Java免费学习笔记(深入)”;
以上就是java判断list是否包含某个值的详细内容,更多请关注php中文网其它相关文章!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号