https://grokonez.com/java/java-how-to-find-an-element-in-a-java-list-object-by-examples
Java – How to find an element in a Java List Object by Examples
[no_toc]
In the tutorial, we will show how to find an element in a List Object with Java APIs and Google Guava library.
contains()
Signature method:
boolean java.util.List.contains(Object o)
-> Returns true
if the list contains at least one element e
such that Objects.equals(o, e)
.
Example:
List integerList = Arrays.asList(1, 3, 7, 9, 11);
System.out.println(integerList.contains(3));
// true
System.out.println(integerList.contains(4));
// false
Example with Custom Object
- Define a Customer class:
More at:
https://grokonez.com/java/java-how-to-find-an-element-in-a-java-list-object-by-examples
Java – How to find an element in a Java List Object by Examples
Top comments (0)