Fast find exist in list or not I want to determine whether or not the selected element exists in the list. This is the current procedure that I'm using for finding the element exist in a list or array. Is there any fast procedure for finding an element with any of these?

int[] array = { 1,2,9,3,5,6,7,8,10};

boolean isFound = false;
for(int i =0; i&lt; array.length;i++) {
    if(array[i] == 4 || array[i] == 9) {
      isFound = true;
      break;
    }
}
System.out.println(isFound);
This strictly depends on the use case. If your list:


Doesn't change
Holds a lot of data
Is being searched many times
And you don't care about where the element is


Then it may be worth keeping a cached sorted copy of the list and using Arrays.binarySearch() on it.

If those conditions are not met, then you're better off just doing a linear search. Of course you can't go lower than O(n) time, because you have to check every element if the list is not sorted.