contains() Method : Java.util.ArrayList
Declaration :
1 |
public boolean contains(Object obj) |
Explanation :
Purpose | Method returns true if this list contains the specified element |
Parameters | obj ==> The element whose presence in this list is to be tested |
Return Value | True if this list contains the specified element |
Exception | NA |
Example
The following example shows the usage of java.util.Arraylist.contains(E) method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
package com.c4learn.arraylist; import java.util.ArrayList; public class ArrayListExamples { public static void main(String args[]) { // Create ArrayList 1 ArrayList<String> arrlist1 = new ArrayList<String>(5); // Fill Elements in ArrayList 1 arrlist1.add("A"); arrlist1.add("B"); arrlist1.add("C"); // Check whether List contains "B" Boolean b1 = arrlist1.contains("B"); if(b1 == true) System.out.println("Element present"); else System.out.println("Element absent"); } } |
Output :
1 |
Element present |