how to know if the array element are specific number and the same in java code example
Example 1: java check if element exists in array
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"};
List<String> list = Arrays.asList(alphabet);
if(list.contains("A")){
System.out.println("Hello A");
}
}
}
Copy
Example 2: java check if element exists in array
boolean result = Arrays.stream(alphabet).anyMatch("A"::equals);
if (result) {
System.out.println("Hello A");
}
Copy
Example 3: arrays .contains methof
private static final Set<String> VALUES = Set.of(
"AB","BC","CD","AE"
);