Solved

Assume That Bands Is an ArrayList of String Objects Which

Question 92

Multiple Choice

Assume that bands is an ArrayList of String objects which contains a number of elements in ascending order. Select a statement to complete the code segment below, which invokes the Java library binarySearch method to search for the string "Beatles". If the list does not already contain the string, it should be inserted in an appropriate location so that the list remains sorted.
Int index = Collections.binarySearch(bands, "Beatles") ;
If (index < 0)
{
__________________________
}


A) bands.add(-1 * index + 1, "Beatles") ;
B) bands.add(index + 1, "Beatles") ;
C) bands.add(-1 * index, "Beatles") ;
D) bands.add(-1 - index, "Beatles") ;

Correct Answer:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions

Unlock this Answer For Free Now!

View this answer and more for free by performing one of the following actions

qr-code

Scan the QR code to install the App and get 2 free unlocks

upload documents

Unlock quizzes for free by uploading documents