| Author |
doubts regarding java.util.Arrays
|
asha ganapathy
Ranch Hand
Joined: Nov 03, 2006
Posts: 54
|
|
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? Thanks in advance
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12924
|
|
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. 2) See Understanding Instance and Class Members in The Java Tutorial.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: doubts regarding java.util.Arrays
|
|
|