Menu

Dsa Java
📰

Dsa Java

DEV Community: java·Esakki Muthu A·10 days ago
#NvOZkIqw
#devtojava#devto#dev#array#target
Reading 0:00
15s threshold

Esakki Muthu A

Linear Search -This is a one of the method used for search a array
we can search entire array and it will work on the sorted array and unsorted array .it's the usefull one in dsa for me also.
public class LinearSearchExample {
public static int linearSearch(int[] arr, int target) {
for (int i = 0; i < arr.length; i++) {
if (arr[i] == target) {
return i; // Return the index where target is found
}
}
return -1; // Target not found
}
}