Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that Objects.equals(o, e).
Examples
package com.logicbig.example.arraylist;
import java.util.*;
public class ContainsExample {
public static void main(String... args) { // Check if element exists ArrayList<String> colors = new ArrayList<>(Arrays.asList("Red", "Green", "Blue")); boolean hasRed = colors.contains("Red"); boolean hasYellow = colors.contains("Yellow"); System.out.println("Contains Red? " + hasRed); System.out.println("Contains Yellow? " + hasYellow); } }