About Question enthuware.ocpjp.v7.2.1306 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
jagoneye
Posts: 97
Joined: Wed Dec 28, 2016 9:00 am
Contact:

About Question enthuware.ocpjp.v7.2.1306 :

Post by jagoneye »

Can you please explain to me what is the purpose of this method??

Code: Select all

binarySearch(T[] a, T key, Comparator<? super T> c)
Why do you need to provide a Comparator when the requirement to search is that
you need the array or the list to be sorted first and you can use the Comparator
during sorting. So i don't understand the practical use of this method.
Another question is that in case of this question, if I pass anything other than String in binarysearch say

Code: Select all

Arrays.binarySearch(sa, 5)
it compiles without any errors whereas if the same array was of primitive type it
doesn't compile if I pass other than the primitive type. I'm guessing it has something to do with strongly typed primitive arrays while String not being a data type.

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1306 :

Post by admin »

1. How will you compare the object that you are searching for with the objects in the array?
2. The call in being bound to another binarySearch method binarySearch(Object[] a, Object key)
If you like our products and services, please help us by posting your review here.

waraging
Posts: 2
Joined: Sun Mar 21, 2021 12:27 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1306 :

Post by waraging »

why is the question giving a very ambiguous with the word (independent of each other or together) that make people read that it should be separate answer

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1306 :

Post by admin »

It just means that you could either use each option independently or use them together to achieve the desired output.
If you like our products and services, please help us by posting your review here.

asi-aal
Posts: 10
Joined: Wed Nov 23, 2022 3:40 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1306 :

Post by asi-aal »

waraging wrote:
Fri Apr 02, 2021 2:59 am
why is the question giving a very ambiguous with the word (independent of each other or together) that make people read that it should be separate answer
I agree, for me it sounded the same

pavvel
Posts: 4
Joined: Fri Dec 15, 2023 4:00 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1306 :

Post by pavvel »

I disagree with the words in the question: (independent of each other or together).
We can use only binarySearch in this option. And binarySearch should work with sorted collection to return 2.
So, there is no independent case. Only together will it work.
Am I correct?

admin
Site Admin
Posts: 10043
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1306 :

Post by admin »

The code will print 2 only if you insert both these options together (not independently):
Arrays.sort(sa);
System.out.println(Arrays.binarySearch(sa, "charlie"));

You have to select 2 options.

One could also select System.out.println(Arrays.linearSearch(sa, "andy")); and System.out.println(Arrays.binarySearch(sa, "charlie")) thinking that both will work if they are inserted independently but that would be wrong because neither of them will achieve the goal.

So, the correct answer is to select 3 and 4.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 20 guests