how to check if an array has a certain value code example
Example 1: Check if an array contains an element java
import java.util.Arrays;
String[] array = {"Boto", "Nesto", "Lepta"};
String toSearch = "Nesto";
if (Arrays.toString(array).contains(toSearch)) {
}
String strArray = Array.toString(array);
if (strArray.contains(toSearch)) {
}
int[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
int number = 5;
String checker = Arrays.toString(numbers);
if (checker.contains(Integer.toString(number)) {
}
Example 2: check if array does not contain value javascript
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var n = fruits.includes("Mango");
var n = fruits.includes("Django");
Example 3: java check if element exists in array
boolean result = Arrays.stream(alphabet).anyMatch("A"::equals);
if (result) {
System.out.println("Hello A");
}
Copy