Introduction
In this article, we are going to discuss or describe Java linear searches. This is the simplest method of searching. In this method, the element to be searched is sequentially searched in the list. This method can be applied to a sorted or an unsorted list.
Linear Search (Sequential Search)
A sequential search of a list/array begins at the beginning of the list/array and continues until the item is found or the entire list/array has been searched. A linear search (aka Sequential Search) is the most fundamental and important of all algorithms. It is simple to understand and implement.
The following figure specifies how a linear search actually works.

Linear Search Algorithms
Step 1: Take a search element into key elements and start the search in the list.
- System.out.print("\nEnter Search Key : ");
- System.out.flush();
- try
- {
- BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
- str = obj.readLine();
- key = Integer.parseInt(str);
- }
- for (int i = 0; i < size; i++{
- if (seaArr[i] == key)
- return (i + 1);
- }
Step 4: If the increment reaches the end of the link or array and a match was not found then return a message such as "Not found".
Example


Join the conversation! Your thoughts help the community grow.