java类库详细讲解
源代码在线查看: coll_findobjectinarray.html
Finding an Element in a Sorted Array
(Java Developers Almanac Example)
BODY CODE {font-family: Courier, Monospace; font-size: 11pt} TABLE, BODY {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt} PRE {font-family: Courier, Monospace; font-size: 10pt} H3 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11pt} A.eglink {text-decoration: none} A:hover.eglink {text-decoration: underline} -->
The Java Developers Almanac 1.4
Order this book from Amazon.
Home
>
List of Packages
>
java.util
[49 examples]
>
Sorted Collections
[5 examples]
e360.
Finding an Element in a Sorted Array
This example also works if the object is a primitive type.
int index = Arrays.binarySearch(sortedArray, object);
if (index < 0) {
// not found
}
Related Examples
e358.
Creating a Sorted Set
e359.
Sorting an Array
e361.
Finding an Element in a Sorted List
e362.
Inserting an Element into a Sorted List
See also:
Arrays
Bits
Collections
Dates
Hash Tables
Lists
Property Files
Sets
Time
Timers
© 2002 Addison-Wesley.