Answers for "java check if arraylist contains"

0

how to check if an element is in arraylist java

// creating an Empty Integer ArrayList
        ArrayList<Integer> arr = new ArrayList<Integer>(4);
// using add() to initialize values
// [1, 2, 3, 4]
        arr.add(1);
        arr.add(2);
        arr.add(3);
        arr.add(4); 
// use contains() to check if the element
// 2 exits or not
        boolean ans = arr.contains(2);
Posted by: Guest on June-21-2021

Code answers related to "java check if arraylist contains"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language