In which Java's library is binary search tree found ?

Recommended Answers

All 2 Replies

You can try Collections.binarySearch(list,elementToSearch); However you need to sort the list first. So you can use:

Collections.sort(arrayList);
Collections.binarySearch(arrayList,elementToSearch);

If the element is found, then it will return the index,else it will return
(-X-1),where X is the position that the element will take in the sorted list.

In which Java's library is binary search tree found ?

I like TreeList from apache-collections
it implements the java.util.List interface, thus you can use as a List. But it is few times faster as ArrayList if you want to change it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.