DEV Community

Discussion on: Check whether a number is in an array or not using recursion

Collapse
 
cess11 profile image
PNS11

Does Java have tail call optimisation now? If not, what are the advantages to this approach compared to Arrays.binarySearch(arr, find), Arrays.asList(arr).contains(find) or the various stream-related techniques?

Collapse
 
yeshrajawat profile image
Yesh Rajawat

No, Java does not support tail call optimization, and we cannot use Arrays.binarySearch(arr, find) as first we will have to sort the array first as binary search works only on sorted arrays. As far as Arrays.asList(arr) concern we first have to convert our array into Arraylist which would definately take time so solving it like this would be better than Arrays.asList(arr).contains(find). But if we have array list instead of fixed size array then we can go for that option.