First, go to list, then use the Contains () method
New String[] {"A", "B", "C"}; = "C"; List<String> list = arrays.aslist (strarr); Boolean result = list.contains (str); // true
Second, use the most basic for loop
The For loop method is the most efficient
New String[] {"A", "B", "C" }; = "C"; for (int i = 0; i < strarr.length; i++) { if (Strarr[i].equals (str)) { SYSTEM.OUT.PRINTLN (// The element in the array: i=2 } }
Third, use Apache Commons's Arrayutils
The Apache Commons Class library has a lot, and almost most of the open source framework relies on it, and the tools in Commons save you most of the time, it contains some common static methods and Java extensions. is a set of frameworks for improving efficiency in development.
New String[] {"A", "B", "C" }; = "C"; Boolean result =//Recommended // true
https://www.programcreek.com/2014/04/check-if-array-contains-a-value-java/
Java determines whether an element is inside an array