You could simply use ArrayUtils.contains from Apache Commons Lang library.

public boolean contains(final int[] array, final int key) {     
    return ArrayUtils.contains(array, key);
}
Answer from Reimeus on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › check-if-a-value-is-present-in-an-array-in-java
Check If a Value is Present in an Array in Java - GeeksforGeeks
// Java program to check if an element is present using List.contains() import java.util.Arrays; class Geeks { private static boolean isElementPresent(Integer[] arr, int key) { return Arrays.asList(arr).contains(key); } public static void main(String[] args) { Integer[] arr = {3, 5, 7, 2, 6, 10}; int key = 7; boolean res = isElementPresent(arr, key); System.out.println("Is " + key + " present in the array: " + res); } } Output ·
Published   November 10, 2025
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-array-contains-value
How to Check if a Java Array Contains a Value? | DigitalOcean
September 16, 2025 - This comprehensive guide covers the four essential methods every Java developer should know: the enhanced for-loop that works in any situation, the convenient Arrays.asList().contains() method for quick lookups in object arrays, modern Java 8 Streams with their functional programming power, and the lightning-fast binary search for sorted arrays. You’ll discover how to handle both primitive arrays like int[] and object arrays like String[], avoid common pitfalls that can break your code, and understand the performance implications of each approach.
🌐
Programiz
programiz.com › java-programming › examples › array-contains-value
Java Program to Check if An Array Contains a Given Value
In the above program, we have an array of integers stored in variable num. Likewise, the number to be found is stored in toFind. Now, we use a for-each loop to iterate through all elements of num and check individually if toFind is equal to n or not. If yes, we set found to true and break from the loop. If not, we move to the next iteration. import java.util.stream.IntStream; class Main { public static void main(String[] args) { int[] num = {1, 2, 3, 4, 5}; int toFind = 7; boolean found = IntStream.of(num).anyMatch(n -> n == toFind); if(found) System.out.println(toFind + " is found."); else System.out.println(toFind + " is not found."); } } Output ·
🌐
TutorialsPoint
tutorialspoint.com › ints-contains-function-in-java
Ints contains() function in Java
Following is an example to implement the contains() method of the Ints class − · import com.google.common.primitives.Ints; import java.util.*; class Demo { public static void main(String[] args) { int[] myArr1 = { 100, 150, 230, 300, 400 }; int[] myArr2 = { 450, 550, 700, 800, 1000 }; ...
Top answer
1 of 16
3431
Arrays.asList(yourArray).contains(yourValue)

Warning: this doesn't work for arrays of primitives (see the comments).


Since java-8 you can now use Streams.

String[] values = {"AB","BC","CD","AE"};
boolean contains = Arrays.stream(values).anyMatch("s"::equals);

To check whether an array of int, double or long contains a value use IntStream, DoubleStream or LongStream respectively.

Example

int[] a = {1,2,3,4};
boolean contains = IntStream.of(a).anyMatch(x -> x == 4);
2 of 16
464

Concise update for Java SE 9

Reference arrays are bad. For this case we are after a set. Since Java SE 9 we have Set.of.

private static final Set<String> VALUES = Set.of(
    "AB","BC","CD","AE"
);

"Given String s, is there a good way of testing whether VALUES contains s?"

VALUES.contains(s)

O(1).

The right type, immutable, O(1) and concise. Beautiful.*

Original answer details

Just to clear the code up to start with. We have (corrected):

public static final String[] VALUES = new String[] {"AB","BC","CD","AE"};

This is a mutable static which FindBugs will tell you is very naughty. Do not modify statics and do not allow other code to do so also. At an absolute minimum, the field should be private:

private static final String[] VALUES = new String[] {"AB","BC","CD","AE"};

(Note, you can actually drop the new String[]; bit.)

Reference arrays are still bad and we want a set:

private static final Set<String> VALUES = new HashSet<String>(Arrays.asList(
     new String[] {"AB","BC","CD","AE"}
));

(Paranoid people, such as myself, may feel more at ease if this was wrapped in Collections.unmodifiableSet - it could then even be made public.)

(*To be a little more on brand, the collections API is predictably still missing immutable collection types and the syntax is still far too verbose, for my tastes.)

🌐
Quora
quora.com › Can-you-make-an-array-that-contains-an-int-and-string-in-Java
Can you make an array that contains an int and string in Java? - Quora
Answer (1 of 6): Sort of. If you’re referring to the int primitive, no, you cannot. Arrays have to have a single type for all the elements they contain. However, if you’re referring to the Integer object, you can, by declaring an Array to ...
🌐
Stack Abuse
stackabuse.com › java-check-if-array-contains-value-or-element
Java: Check if Array Contains Value or Element
November 19, 2020 - There are various ways to convert a Java array to an ArrayList, though, we'll be using the most widely used approach. Then, we can use the contains() method on the resulting ArrayList, which returns a boolean signifying if the list contains the element we've passed to it or not.
🌐
Delft Stack
delftstack.com › home › howto › java › java array contains int
How to Check if an Array Contains Int in Java | Delft Stack
February 2, 2024 - \n" + val); } public static boolean contains(final int[] arr, final int key) { return ArrayUtils.contains(arr, key); } } ... We can convert the array to the list using Arrays.asList() and then use the list’s contains() method to find the specified value in the given array. This method returns a boolean value, either true or false. It takes a value as an argument that needs to be found. See the example below. import java.util.Arrays; public class SimpleTesting { public static void main(String[] args) { int[] arr = {10, 25, 23, 14, 85, 65}; int key = 14; boolean val = contains(arr, key); System.out.println("Array contains " + key + "?
Find elsewhere
🌐
Crunchify
crunchify.com › java j2ee tutorials › 4 ways to check if an array contains a specific value – intstream, arrays.aslist (linear search algorithm)
4 Ways to Check if an Array Contains a Specific Value - IntStream, Arrays.asList (Linear Search Algorithm) • Crunchify
November 17, 2022 - Test-4: Perform same contains check using Arrays.asList() method · Copy complete below program in Eclipse IDE. package crunchify.com.tutorials; import java.util.Arrays; import java.util.List; import java.util.stream.IntStream; import java.util.stream.LongStream; /** * @author Crunchify.com * version: 1.0 */ public class CrunchifyCheckIfContains { public static void main(String[] args) { int crunchifyRandomNo; // Let's create integer array with 15 values in it int[] crunchifyIntArray = new int[15]; for (int i = 1; i <= 14; i++) { crunchifyRandomNo = (7 + (int) (Math.random() * ((95 - 7)))); cr
🌐
Mkyong
mkyong.com › home › java › java – check if array contains a certain value?
Java - Check if Array contains a certain value? - Mkyong.com
November 19, 2016 - Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities. ... The link of the topic does not match the title. ... for 1.1 you could do Arrays.stream(alphabet).filter(“A”::equals).findAny().ifPresent(s->System.out.println(“Hello A”)); ... static boolean contains(Integer[] ints, int k) { return (java.util.Arrays.binarySearch(ints, k)) >= 0; }
🌐
w3resource
w3resource.com › java-exercises › array › java-array-exercise-5.php
Java - Test if an array contains a specific value
Pictorial Presentation: Sample ... that checks if an integer array 'arr' contains a given 'item'. public static boolean contains(int[] arr, int item) { // Iterate through each element 'n' in the array 'arr'. for (int n ...
🌐
AlgoCademy
algocademy.com › link
Array Contains in Java | AlgoCademy
Jump Game in Java · Given an array of integers nums and another integer value, check if value occurs in nums. If the value occurs in nums, return true; otherwise return false. Examples: contains([1, 2, 4, 5], 4) -> true contains([-1, 2, -4, ...
🌐
YouTube
youtube.com › watch
Java Program to Check if An Array Contains a Given Value - YouTube
#javaarray #java #array Java Program to Check if An Array Contains a Given ValueAll Java Programs | Java Coding Interview Questions:https://www.youtube.com/p...
Published   November 17, 2024
🌐
Java67
java67.com › 2014 › 11 › how-to-test-if-array-contains-certain-value-in-java.html
How to check if Array contains given Number or String in Java [ Linear Search vs Binary Search] | Java67
As I told you, if you are allowed to use Java API, then you can either use the binarySearch() method of Java Java .util.Arrays class or you can simply convert your array to ArrayList and then call its contains() method.
🌐
Attacomsian
attacomsian.com › blog › java-array-contains-value
How to check if an array contains a value in Java
December 1, 2019 - String[] names = {"Atta", "John", "Emma", "Tom"}; // convert array to list List<String> list = Arrays.asList(names); // check 'Atta' & `John` if (list.containsAll(Arrays.asList("Atta", "John"))) { System.out.println("Hi, Atta & John 🎉"); } ... int[] years = {2015, 2016, 2017, 2018, 2019, 2020}; // loop all elements for (int y : years) { if (y == 2019) { System.out.println("Goodbye, 2019!"); break; } } ... Goodbye, 2019! With Java 8 or higher, you can convert the primitive array to a Stream and then check if it contains a certain value as shown below:
🌐
Vultr Docs
docs.vultr.com › java › examples › check-if-an-array-contains-a-given-value
Java Program to Check if An Array Contains a Given Value | Vultr Docs
December 20, 2024 - public class Main { public static void main(String[] args) { int[] array = {1, 2, 3, 4, 5}; int valueToFind = 3; boolean found = false; for (int element : array) { if (element == valueToFind) { found = true; break; } } System.out.println("Value found: " + found); } } Explain Code · In this version, the enhanced for loop iterates directly over each element, eliminating the need for index manipulation. Utilize Java Stream API introduced in Java 8 to check for the presence of a value in a more functional style.
🌐
Sentry
sentry.io › sentry answers › java › find a specific value in an array in java
Find a specific value in an array in Java | Sentry
Note that if we attempt this same approach with an array of primitive types, the contains method will not throw an error, but will always return false, even if the array contains the value we specify. We can run the code below to verify this: ... // BROKEN CODE DO NOT USE import java.util.Arrays; public class Main { public static void main(String[] args) { int[] values = {1, 2, 3, 4, 5}; if (Arrays.asList(values).contains(3)) { System.out.println("Array contains 3!"); } else { // this block will be executed System.out.println("Array does not contain 3."); } } } // BROKEN CODE DO NOT USE