SlideShare ist ein Scribd-Unternehmen logo
1 von 2
19) 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");
Solution
Ans: d) bands.add(-1 - index, "Beatles");
Explanation:
int index = Collections.binarySearch(bands, "Beatles");
Returns:
the index of the search key, if it is contained in the list; otherwise, (-(insertion point) - 1). The
insertion point is defined as the point at which the key would be inserted into the list: the index
of the first element greater than the key, or list.size() if all elements in the list are less than the
specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is
found.
19) Assume that bands is an ArrayList of String objects which contains.docx

Weitere ähnliche Inhalte

Mehr von lcarolyn

1Experimental Chemistry Data Analysis 1- How do you know when to name.docx
1Experimental Chemistry Data Analysis 1- How do you know when to name.docx1Experimental Chemistry Data Analysis 1- How do you know when to name.docx
1Experimental Chemistry Data Analysis 1- How do you know when to name.docxlcarolyn
 
18) Explain why oil and water do not mix- A) Water is not able to ioni.docx
18) Explain why oil and water do not mix- A) Water is not able to ioni.docx18) Explain why oil and water do not mix- A) Water is not able to ioni.docx
18) Explain why oil and water do not mix- A) Water is not able to ioni.docxlcarolyn
 
17-Calcium sulfate has a soluble form in water- formed according to-.docx
17-Calcium sulfate has a soluble form in water- formed according to-.docx17-Calcium sulfate has a soluble form in water- formed according to-.docx
17-Calcium sulfate has a soluble form in water- formed according to-.docxlcarolyn
 
2- Does evolution violate the second law of thermodynamics- Why or why.docx
2- Does evolution violate the second law of thermodynamics- Why or why.docx2- Does evolution violate the second law of thermodynamics- Why or why.docx
2- Does evolution violate the second law of thermodynamics- Why or why.docxlcarolyn
 
2- Discuss the advantages and disadvantages of using the following com.docx
2- Discuss the advantages and disadvantages of using the following com.docx2- Discuss the advantages and disadvantages of using the following com.docx
2- Discuss the advantages and disadvantages of using the following com.docxlcarolyn
 
2- Create a multi - step Income Statement- Statement of Retained Earni.docx
2- Create a multi - step Income Statement- Statement of Retained Earni.docx2- Create a multi - step Income Statement- Statement of Retained Earni.docx
2- Create a multi - step Income Statement- Statement of Retained Earni.docxlcarolyn
 
2- Compare teh payment of cash divididends- stock dividends and purcha.docx
2- Compare teh payment of cash divididends- stock dividends and purcha.docx2- Compare teh payment of cash divididends- stock dividends and purcha.docx
2- Compare teh payment of cash divididends- stock dividends and purcha.docxlcarolyn
 

Mehr von lcarolyn (7)

1Experimental Chemistry Data Analysis 1- How do you know when to name.docx
1Experimental Chemistry Data Analysis 1- How do you know when to name.docx1Experimental Chemistry Data Analysis 1- How do you know when to name.docx
1Experimental Chemistry Data Analysis 1- How do you know when to name.docx
 
18) Explain why oil and water do not mix- A) Water is not able to ioni.docx
18) Explain why oil and water do not mix- A) Water is not able to ioni.docx18) Explain why oil and water do not mix- A) Water is not able to ioni.docx
18) Explain why oil and water do not mix- A) Water is not able to ioni.docx
 
17-Calcium sulfate has a soluble form in water- formed according to-.docx
17-Calcium sulfate has a soluble form in water- formed according to-.docx17-Calcium sulfate has a soluble form in water- formed according to-.docx
17-Calcium sulfate has a soluble form in water- formed according to-.docx
 
2- Does evolution violate the second law of thermodynamics- Why or why.docx
2- Does evolution violate the second law of thermodynamics- Why or why.docx2- Does evolution violate the second law of thermodynamics- Why or why.docx
2- Does evolution violate the second law of thermodynamics- Why or why.docx
 
2- Discuss the advantages and disadvantages of using the following com.docx
2- Discuss the advantages and disadvantages of using the following com.docx2- Discuss the advantages and disadvantages of using the following com.docx
2- Discuss the advantages and disadvantages of using the following com.docx
 
2- Create a multi - step Income Statement- Statement of Retained Earni.docx
2- Create a multi - step Income Statement- Statement of Retained Earni.docx2- Create a multi - step Income Statement- Statement of Retained Earni.docx
2- Create a multi - step Income Statement- Statement of Retained Earni.docx
 
2- Compare teh payment of cash divididends- stock dividends and purcha.docx
2- Compare teh payment of cash divididends- stock dividends and purcha.docx2- Compare teh payment of cash divididends- stock dividends and purcha.docx
2- Compare teh payment of cash divididends- stock dividends and purcha.docx
 

Kürzlich hochgeladen

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 

Kürzlich hochgeladen (20)

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 

19) Assume that bands is an ArrayList of String objects which contains.docx

  • 1. 19) 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"); Solution Ans: d) bands.add(-1 - index, "Beatles"); Explanation: int index = Collections.binarySearch(bands, "Beatles"); Returns: the index of the search key, if it is contained in the list; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the list: the index of the first element greater than the key, or list.size() if all elements in the list are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.