One of the common coding question from Java interviews is how to test if an Array contains a certain value or not? This is simple question but some time interview pressure makes candidates nervous. Since array in Java doesn't have any inbuilt method for search, interviewer prefer to ask this question, to see how candidate deal with such situation. If you have good knowledge of Java API then you will immediately come to know that there are alternatives available e.g. binary search of Arrays class or taking advantage of
ArrayList contains method by first converting your array to ArrayList. If you come up with those solution, Interviewer will surely ask you to write down a method to search an element in array without using any library method. You can easily solve this question if you know linear search or binary search algorithm. Linear search is very simple to implement, all you need to do is loop over array and check each value if that is the one or not. Binary search is little tricky but not too difficult either, recursive version is very natural as well. In this tutorial, though I have given two solution, one is using ArrayList, and second is using linear search, leaving binary search an exercise for you. But you must remember to sort array before using binary search. By the way to make question more challenging, I usually asked candidate to
write a parametric method using generic so that it will work for any type of object array in Java.