Home > Java > JavaBase > Java determines whether list contains a certain value

Java determines whether list contains a certain value

王林
Release: 2019-11-18 13:26:32
Original
11233 people have browsed it

Java determines whether list contains a certain value

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);
Copy after login

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());
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template