今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Finding elements in a collection
- [Instructor] The collections class contains many static methods that help us work with the collection. In this lesson, we're going to explore a few of them that allow us to find values within a list. So let's start out with the classic binary search. When we use a binary search method in the collections framework, we need our collection to be sorted. So you'll notice that I have a list of rooms and then I've used our rate comparator to sort them. So let's go ahead and on the collections class, we can invoke the binary search method. And you'll notice that there's two of them. The first, we'll use the natural sort order of the collection in order to perform the search. The other one will accept a comparator. Now because we're not using the natural sort order of a room for our collection, we'll need to go with this form of the method. So the first argument's the collection that you would like to search. The second argument…