This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes doubts regarding java.util.Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "doubts regarding java.util.Arrays" Watch "doubts regarding java.util.Arrays" New topic
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
    
    3

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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: doubts regarding java.util.Arrays
 
Similar Threads
Comparator's compare() method question
Comparator interface
Static question
Searching Arrays and Collections
Comparator interface