2017  Kodetalk | Feedback | Privacy Policy | Terms | About

how to check an element exist in an array using java

I have an array as below:

String[] data = {"now", "i want", "tested"};

Now my issue is i want to check if an element exist in the array. What is the best way as i am doing this using for loop. I want to avoid for loop.


Probably you should try as below:

Arrays.asList(data).contains(<your data that need to be checked>) // will return the boolean type

Answer is