Hire QA – Specialized in QA Recruitment, Technical Interviews and Testing Solutions

How to decide between HashMap and TreeMap?

Category: Java

For inserting, deleting, and locating elements in a Map, the HashMap offers the best alternative. If, however, you need to traverse the keys in a sorted order, then TreeMap is your better alternative. Depending upon the size of your collection, it may be faster to add elements to a HashMap, then convert the map to a TreeMap for sorted key traversal.

Leave a Reply

Your email address will not be published. Required fields are marked *