programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# k&b scjp5, page no 616, problem no 9

Mukesh Gulia
Greenhorn
Posts: 2
Given a properly prepared String array containing five elements, which range of results could a proper invocation of Arrays.binarySearch()produce?

a. 0 through 4
b. 0 through 5
c. -1 through 4
d. -1 through 5
e. -5 through 4
f. -5 through 5
g. -6 through 4
h. -6 through 5

ans is G.
i thought answer is be E

range can be ((-5) -1) through 4 i.e. 4 to 4
negative result give insertion point(array index).

Brij Garg
Ranch Hand
Posts: 234
If you know

range can be ((-5) -1) through 4 i.e. 4 to 4

then range is -6 to 4.

sweety sinha
Ranch Hand
Posts: 76

............................................................................

range can be ((-5) -1) through 4 i.e.
((-5)+(-1))= (-5-1)= -6
i.e range can be -6 through 4

you did a slight mistake in adding.

Mukesh Gulia
Greenhorn
Posts: 2
yeah yeah
thanks all