I have a code like this:
List Listings = new ArrayList<>();
Listings.add(listing1);
Listings.add(listing2);
...
...
...
Listing listing= li
The worst case is O(n)
but since Stream
is lazy, if the value is found before, it'll stop the iteration. If you need constant time look up, all the time, converting to a Map
is a good idea, at the cost of additional space; if the list if huge, you should consider that aspect. In fact, if the list is small, the difference between a Map
and a List
will be barely noticeable, unless you're working in a time-critical system.