Note that the keys are sorted in a natural ordering. You can use that to stop iterating through the keys once the condition has been met