- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Linear search in Java.
Following is the required program.
Example
public class Tester { public static int linearSearch(int[] arr, int element) { for (int i = 0; i < arr.length; i++) { if (arr[i] == element) { return i; } } return -1; } public static void main(String a[]) { int[] array = { 10, 20, 30, 50, 70, 90 }; int element = 50; int index = linearSearch(array, element); if (index != -1) { System.out.println(element + " present at index: " +index); } else { System.out.println(element + " is not present."); } } }
Output
50 present at index: 3
- Related Articles
- Java program to implement linear search
- Linear Search
- Linear Search in Python Program
- Implementing Linear Search in JavaScript
- Difference Between Linear Search and Binary Search
- Python Program for Linear Search
- Linear search using Multi-threading in C
- 8085 Program to perform linear search
- C/C++ Program for Linear Search?
- Program to perform linear search in 8085 Microprocessor
- Linear search on list or tuples in Python
- Write a program for Linear Search in Python
- Binary search in Java.
- C++ Program to Find Minimum Element in an Array using Linear Search
- How to find minimum element in an array using linear search in C language?

Advertisements