In this program, you'll learn to Search Key Elements in the given arrays in Java.
Search an element in an array Find an element from an array using Linear Searching. Linear searching is a good way to find an element from the array. The array can be of any order, it checks whether a certain element (number , string , etc. ) is in a specified array or not. Basically it is used for small arrays. In the given code, we have allowed the user to enter the numbers to be stored into the arrays. If the element is found we can return the index where the element is located in the array. If the element is not found we can return -1.
Search Key Elements in an Array
When you run the program, the output will be:
The contents of the Array are :Array[0] = 11Array[1] = -10Array[2] = 25Array[3] = 18Array[4] = 45Array[5] = 55Array[6] = 30Array[7] = 87Array[8] = -28Array[9] = 18The search element is : 55It is found in the array at position : 5