I am trying to validate password and username using array and the array.BinarySearch function. The first two user names in the array: bradley and john are returning the correct
Your names
array is not sorted:
String[] names = {"bradley","john","jim","clarke"};
which is a requirement of binarySearch() (and binary searching algorithm in general):
The range must be sorted into ascending order
Sort it first and it'll work like a charm:
String[] names = {"bradley","clarke","jim","john"};