how to check an arraylist contains a value in java

In this post we see how to check if value exists in list in java . arraylist.contains() mehtod use for check java arraylist contains element or not . arraylist contains() Method returns true if this list contains the given element. means , returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)).

Systax :

public boolean contains(Object o) {

  • Parameters:
    o element whose presence in this list is to be teste
  • Returns Value :
    true if this list contains the specified element

Java ArrayList contains() Method example

import java.util.ArrayList;

public class ContailsElement {

public static void main(String[] args) {

ArrayList<String> arr = new ArrayList<String>();
// add element in arraylist
// print arraylist
System.out.println("arrayList is = " + arr);
* Returns true if this list contains the specified element




arrayList is = [c, php, html, java]



So , Here we have learned How to check if an ArrayList contains a value in Java and This method also use for to check if an arraylist does not contain a value in java .

Java Arraylist GuideĀ 

Leave a Reply

Your email address will not be published. Required fields are marked *

− 2 = 6