Check out example codes for "java check if element exists in array". It will help you in understanding the concepts better.

Code Example 1

for (int element : arr) {
    if (element == toCheckValue) {
        return true;
    }
}

Code Example 2

// Convert to stream and test it
	boolean result = Arrays.stream(alphabet).anyMatch("A"::equals);
	if (result) {
		System.out.println("Hello A");
	}
Copy

Code Example 3

package com.mkyong.core;

import java.util.Arrays;
import java.util.List;

public class StringArrayExample1 {

    public static void main(String[] args) {

        String[] alphabet = new String[]{"A", "B", "C"};

        // Convert String Array to List
        List<String> list = Arrays.asList(alphabet);
        
        if(list.contains("A")){
            System.out.println("Hello A");
        }

    }

}
Copy

Learn ReactJs, React Native from akashmittal.com