I must be missing something very obvious, but I’ve searched all over and can’t find this method.
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.
There are a couple of ways to accomplish this using the
Arraysutility class.If the array is not sorted and is not an array of primitives:
If the array is primitives and not sorted, one should use a solution offered by one of the other answers such as Kerem Baydoğan’s, Andrew McKinlay’s or Mishax’s. The above code will compile even if
theArrayis primitive (possibly emitting a warning) but you’ll get totally incorrect results nonetheless.If the array is sorted, you can make use of a binary search for performance: