There is a contains method for lists, so you should be able to do:

Arrays.asList(yourArray).contains(yourObject);

Warning: this might not do what you (or I) expect, see Tom's comment below.

Answer from Douglas on Stack Overflow
🌐
Medium
medium.com › @f2015939p › search-an-element-in-the-array-913b616f315f
Search an element in the array. In Java, you can search for an element… | by DIKCHHA AGRAWAL | Medium
April 25, 2023 - Search an element in the array In Java, you can search for an element in an array using a loop that iterates through the elements of the array and checks if each element is equal to the element you …
Discussions

A better way to find the index of an element in an array?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
23
3
August 27, 2022
Java - Find Element in Array using Condition and Lambda - Stack Overflow
In short, I have this code, and ... specific element of the array using a condition and lambda. The code would be something like this: Preset[] presets = presetDALC.getList(); Preset preset = Arrays.stream(presets).select(x -> x.getName().equals("MyString")); But obviously this does not work. In C# would be something similar but in Java, how do I do this? ... Optional optional = Arrays.stream(presets) .filter(x -> "MyString".equals(x.getName())) .findFirst(); // Check ... More on stackoverflow.com
🌐 stackoverflow.com
Java while loop to find index of elements in ArrayList
ArrayList.indexOf(Object o) will always return the index of the first occurrence of the given object, so what you observe is happening by design; to get the indices of the others, you would have to remove the item from the list once you find it so that when you call indexOf again, the next occurrence is seen. Alternatively, you could scan through the list and compare elements directly instead of using indexOf. That way, you wouldn't have to modify the list at all, since you'd simply be looking at each item and comparing with a reference value. More on reddit.com
🌐 r/learnprogramming
13
1
May 4, 2017
[java] How to access the last element in a two dimensional array of unknown size?
A two dimensional array is just an array of arrays, so to get the last item in the last row, you can get the last array from the first dimension, and get that array's last item: int[] lastRow = array[array.length - 1]; int lastItem = lastRow[lastRow.length - 1]; Or you can get the last row's length, and access the last row & column from the 2D array: int lastRowLength = array[array.length - 1].length; int lastItem = array[array.length - 1][lastRowLength - 1]; or more concisely: int lastItem = array[array.length - 1][array[array.length-1].length - 1]; Edit: typo fixed. thanks to u/HellloWorld More on reddit.com
🌐 r/learnprogramming
5
0
May 16, 2013
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java › apache › commons › lang3
Find elements in an array - Java Code Geeks
October 7, 2013 - Use the lastIndexOf(Object[] array, Object objectToFind) method to find the last index of the given object within the array. Let’s take a look at the code snippet that follows: package com.javacodegeeks.snippets.core; import org.apache.co...
🌐
Blogger
javarevisited.blogspot.com › 2012 › 11 › 4-ways-to-search-object-in-java-array-example.html
4 Ways to Search Java Array to Find an Element or Object - Tutorial Example
June 27, 2025 - ArrayList in Java has a convenient method called contains() which returns true if the object passed to it are inside ArrayList. by converting an array into ArrayList in Java we can easily use this option for searching any element in Java array.
🌐
Dot Net Perls
dotnetperls.com › find-java
Java - Array Find Element (findFirst) - Dot Net Perls
With findFirst() we can find an element in an array. We first create a stream.
🌐
Baeldung
baeldung.com › home › java › java array › find the index of an element in a java array
Find the Index of an Element in a Java Array | Baeldung
December 7, 2023 - In our test code, we call the intStream() method that we implemented, and we get the index where the target element is placed. If the target element isn’t in the array, then we’ll get -1; At this point, we’ve looked at most of the built-in Java APIs that we can use to find the index of an element in an array.
Find elsewhere
🌐
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
The built-in Arrays.binarySearch() method performs this operation in logarithmic time. ... Return Value: Returns the index of the key if found; otherwise, a negative value. ... import java.util.Arrays; class Geeks { private static boolean ...
Published: August 18, 2026
🌐
Sentry
sentry.io › sentry answers › java › find a specific value in an array in java
Java Find a Specific Value in an Array Using Streams | Sentry
September 23, 2026 - Use the Stream API's anyMatch method to check if a Java array contains a value, or convert the array to a list with Arrays.asList for reference types
🌐
YouTube
youtube.com › watch
How to SEARCH an ARRAY easy! 🔎 - YouTube
#java #javatutorial #javacourse In this video, we're going to be performing a linear search through the elements of an array to find a matching target.
Published: December 5, 2024
🌐
CodeChef
codechef.com › practice › course › arrays › ARRAYS › problems › SEARCHINARR
Search an element in an array Practice Problem in Arrays
Test your Arrays knowledge with our Search an element in an array practice problem. Dive into the world of arrays challenges at CodeChef.
🌐
GeeksforGeeks
geeksforgeeks.org › java › find-the-index-of-an-array-element-in-java
Find the Index of an Array Element in Java - GeeksforGeeks
July 11, 2025 - One of the simplest and most straightforward ways to find the index of an element in an array is by using a loop. You can iterate through the array and compare each element with the target element.
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › searching-elements-in-an-array-array-operations
Searching Elements in an Array | Array Operations - GeeksforGeeks
July 23, 2025 - Note that we compare arr[fibMm2] with x. When fibM becomes 1, fibMm2 becomes 0 */ while (fibM > 1) { // Check if fibMm2 is a valid location int i = minimum(offset + fibMMm2, n - 1); /* If x is greater than the value at index fibMm2, cut the subarray array from offset to i */ if (arr[i] < x) { fibM = fibMMm1; fibMMm1 = fibMMm2; fibMMm2 = fibM - fibMMm1; offset = i; } /* If x is greater than the value at index fibMm2, cut the subarray after i+1 */ else if (arr[i] > x) { fibM = fibMMm2; fibMMm1 = fibMMm1 - fibMMm2; fibMMm2 = fibM - fibMMm1; } /* element found. return index */ else return i; } /*
🌐
w3resource
w3resource.com › java-exercises › collection › java-collection-exercise-7.php
Java - Search an element in a array list
May 21, 2025 - import java.util.*; public class Exercise7 { public static void main(String[] args) { // Creae a list and add some colors to the list List<String> list_Strings = new ArrayList<String>(); list_Strings.add("Red"); list_Strings.add("Green"); list_Strings.add("Orange"); list_Strings.add("White"); list_Strings.add("Black"); // Search the value Red if (list_Strings.contains("Red")) { System.out.println("Found the element"); } else { System.out.println("There is no such element"); } } } ... Write a Java program to search for a specific string in an ArrayList using binary search after sorting the list.
🌐
YouTube
youtube.com › watch
How to search for an element in array in java ? - YouTube
#learnwithkrishnasandeep #javacodinginterviewquestions #javaexamples #javaprograms #javatutorials #javaprogramming find element in array in java,search val...
Published: March 20, 2016
🌐
YouTube
youtube.com › programmingknowledge
How to find index of element in array in java? - YouTube
In this tutorial, you will learn how to find the index of an element in an array in Java. Arrays are a fundamental data structure in Java and are used extens...
Published: March 26, 2023
Views: 6K
🌐
Quora
quora.com › How-do-you-find-out-if-an-element-exists-in-an-array-in-Java
How to find out if an element exists in an array in Java - Quora
Answer (1 of 3): This is very basic array question, you should think about it first so that your skill can improve. Array is a list of values and how do you find a element in that. For example if a bucket contains red apples and one green apple. How do you find green apple from bucket? So the pr...
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-array-contains-value
How to Check if a Java Array Contains a Value? | DigitalOcean
September 16, 2025 - Learn 4 proven methods to check if Java array contains value: for-loops, Streams, Arrays.asList(), and binarySearch(). Choose the right approach today!