Answers for "java find element in list"

5

java stream find specific element

Customer james = customers.stream()
  .filter(customer -> "James".equals(customer.getName()))
  .findAny()
  .orElse(null);
Posted by: Guest on April-06-2020
0

how to find specific elements from a list in java

public Customer findUsingEnhancedForLoop(
  String name, List<Customer> customers) {

    for (Customer customer : customers) {
        if (customer.getName().equals(name)) {
            return customer;
        }
    }
    return null;
}
Posted by: Guest on August-13-2021

Code answers related to "java find element in list"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language