Java Program to Search Key Elements in an Array

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] = 11
Array[1] = -10
Array[2] = 25
Array[3] = 18
Array[4] = 45
Array[5] = 55
Array[6] = 30
Array[7] = 87
Array[8] = -28
Array[9] = 18
The search element is : 55
It is found in the array at position : 5

Previous Post Next Post