I am new to Java. I have a question about the time complexity of java iterator().
Set<Integer> set = new HashSet<>();
Iterator<Integer> iter = set.iterator(); ==> (2)
iterator() is constant time. It is a method call that returns an
Iterator instance on the collection you are calling on. Actually iterating through the collection using the iterator using
while (hasNext()) will be O(n)