java check if element exists in array
for (int element : arr) {
if (element == toCheckValue) {
return true;
}
}
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 // Convert to stream and test it
boolean result = Arrays.stream(alphabet).anyMatch("A"::equals);
if (result) {
System.out.println("Hello A");
}
Copy
Also in Java:
- how to take input in java
- change java version command line debian
- generate all prime number less than n java (fastest method)
- JFrame text java
- java ternary operator
- minecraft sounds spigot
- java file path linux
- start thread java
- how to create gravity in java
- simple calculator program in java
- for each loop java
- j
- how to add element to arraylist
- java stream sorted reverse
- nextchar in java
- tolowercase java
- java character for end of file
- java script removing first three indexes
- java define main function
- append to arraylist by index java
- java how to call getReader twice
- protect java
- for loop in java stack overflow
- how to check type of primitive value in java