The method get(int) in the type List<String> is not applicable for the argument string in Java 8

ids is a List<String> and elem is a String. Therefore ids.get(elem) is invalid, since List has no get method that takes a String.

It should be:

private boolean findIdInTheList(List<String> ids, String id) {
    String theId = ids.stream()
                      .filter(elem -> id.equals(elem))
                      .findAny()
                      .orElse(null);
}

Oh, and since your method has a boolean return type, you should add a return statement.

You can simplify the pipeline with anyMatch:

private boolean findIdInTheList(List<String> ids, String id) {
    return ids.stream()
              .anyMatch(elem -> id.equals(elem));
}

Here you get a boolean that indicates whether id was found in the List. I see no point in returning the String itself, since you already know that it's equal to id.


.filter(elem -> id.equals(elem))

you already have the elem from the source in this Predicate

You can also write it as a method reference:

.filter(id::equals)