using Java. the List is sorted so I want to use binary search. I’d prefer not to write extra code, is there any built-in method to do this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Have you looked at
Collections.binarySearch? That basically does the search part – you’d then need to look at whether the result was negative (i.e. an exact match wasn’t found) and take the bitwise complement if so to find where the item would have been inserted.