There is no faster way ... if you just use a LinkedHashMap
.
If you want faster access, you need to use a different data structure. For example, a TreeSet
with an appropriate comparator might be a better solution for this aspect of your problem. For example if your TreeSet is ordered by date, then calling tailSet
with an appropriate dummy value can give you all elements greater or equal to a given date.
Since the results are already sorted, is there any algorithm I can pass the iterator (or collection to), that can search it faster than sequential?
Not for a LinkedHashMap
.
However, if the ordered list was an ArrayList
instead, then you could use "binary search" on the list ... provided that you could lock it to prevent concurrent modifications while you are searching. (Actually, concurrency is a potential issue to consider no matter how you implement this ... including your current linear search.)
If you want to keep the ability to do id
lookups, then you need two data structures; e.g. a TreeSet
and a HashMap
which share their element objects. A TreeSet
will probably be more efficient than trying to maintain an ArrayList
in order assuming that there are random insertions and/or random deletions.