get distinct values from list of objects java

java get distinct values from list

List<String> distinctElements = list.stream()
                        .distinct()
                        .collect(Collectors.toList());

Source: codegrepper

get distinct values from list of objects java

public Set<String> areas(final List<Employee> employees) {
    Set<String> areas = new HashSet<>();
    for(final Employee employee: employees) {
        areas.add(employee.getArea());
    }
    return areas;
}

Source: stackoverflow.com