ArrayList.contains(Object): This method is available in java.util.ArrayList class of Java.
Syntax:
boolean java.util.ArrayList.contains(Object o)
This method takes one argument . This method returns true if this list contains the specified element.
Parameters: One parameter is required for this method.
o: element whose presence in this list is to be tested.
Returns: true if this list contains the specified element.
Exceptions: NA
Approach
Java
import java.util.ArrayList;public class ArrayListcontains {public static void main(String[] args) {ArrayList<Integer> arr = new ArrayList<>();arr.add(1);arr.add(2);arr.add(3);Integer o = 3;System.out.println(arr.contains(o));}}
Output:
true
No comments:
Post a Comment