File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Master exam question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Master exam question" Watch "Master exam question" New topic

Master exam question

ujjawal rohra
Ranch Hand

Joined: Mar 20, 2010
Posts: 105
Given a properly prepared String array containing five elements,which range
of results could a proper invocation of Arrays.binarySearch() produce?

Ans. -6 through 4

Why is the answer -6.According to me the last insertion point shoule be -5 by the formula
-(insertion point )- 1.
Since the last index must be 4 it becomes -4-1=-5

Correct me if i m wrong

Ankit Garg

Joined: Aug 03, 2008
Posts: 9465

This question has been asked earlier in the forum too. Like here. Search through the forum for previous discussions of this question...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I agree. Here's the link:
subject: Master exam question
It's not a secret anymore!