Someone mentioned here that using linkedHashSet.iterator().next() can get the first element in O(1):
Fetch the most recent inserted element in LinkedHashSet efficiently
But I am thinking why it is O(1), as the code behind the method is: map.keySet().iterator().next(); Shouldn't the iterator() go through every elements before returning the Iterator?
Thank you!