Does using an Iterator over a TreeMap in Java interfere with the order of keys?

11,443

No - it will iterate in the order defined by the TreeMap, i.e. the natural ordering of the keys, or the one imposed by the comparator specified in the constructor. Just iterating won't change that in the underlying tree map, either.

Share:
11,443
Hossein
Author by

Hossein

Updated on June 04, 2022

Comments

  • Hossein
    Hossein almost 2 years

    I want to know that if using an Iterator over a TreeMap in Java interfere with the order of keys?