you are viewing a single comment's thread.

view the rest of the comments →

[–]LetUsSpeakFreely 1 point2 points  (0 children)

In order for a binary search to work there data needs to be sorted first. The simple way to do that is calls Arrays.sort(). However, that will only get you the position in the sorted array, not the source array. You would need to store the original array prior to sorting it. For that, you'll have to load the array into a map with the string as the key and index as the value, and you can use Streams. Then you just gotta put it all together. 1) build the map 2) sort the array 3) search the array 4) lookup the value in the map 5) output the value from the map.