Linear Search in Java with Example

Definition

Linear search is the simplest search algorithm. For a list with n items, the best case is when the value is equal to the first element of the list, in which case only one comparison is needed.

To search any element present inside the array in Java Programming using linear search technique, you have to use only one for loop to check whether the entered number is found in the list or not as shown in the following program.

Example 1:

Output :

 Entr Array Size : 5
 Enter Array elements : 12
 23
 34
 45
 56
 enter the Number to be Search...45
 45 found at position 4

Example 2:

Output:

 15 is found at index: 3