I have few doubts regarding the above code: 1) Why does the search return -1 when "one" is searched in an array of reverse ordered Strings ? 2) I understand the concept of static modifier that its owned by a class and not an object.To use a static method we use the Classname instead of instantiating an object. What i have not understood is: -> what is the use of a static method or variable or a static class? Cant we perform the same operations using objects?
1) Because binarySearch() only works on an array that is sorted according to the natural ordering of the objects in the array. The API documentation for the method Arrays.binarySearch() explains in detail what that means - look it up. It will not work correctly if the array is not sorted according to the natural ordering, as in the case in your code above.