• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Possible Error in SCJP5 - Generics and Collections

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, here is a question 9 on from pg 616 of Bates and Sierra's SCJP Java 5 study guide:

Given a properly prepared String array containing five elements, which range of results coud a proper invocaion of Arrays.binarySearch() produce?

The answer given on page 628 is:

G: -6 through 4

I would think the answer should be:

E: -5 through 4

Isn't the formula for determining the insertion point:



So for an array of 5 elements, the insertion point representing index 4 is:



Am I missing something?

Tim
 
Ranch Hand
Posts: 447
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi


Tim


Here we are searching for one element and the element is not there in the array means,the element which we are searching should be there at fifth position in the array.

so
-(-5)-1=-6

ok

Thanks

Anil Kumar
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,




Thanks,
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

insertion point gives the location of element so that whole array would be sorted one.

So the searching element would be the next of last element of array.
here it's index would be 5.
So insertion point will be -(5)-1 = -6 ..

[ May 17, 2007: Message edited by: lalit chand ]
[ May 17, 2007: Message edited by: lalit chand ]
 
Message for you sir! I think it is a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic