• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

SoftwareTestingo - Interview Questions, Tutorial & Test Cases Template Examples

SoftwareTestingo - Interview Questions, Tutorial & Test Cases Template Examples

  • Home
  • Test Case Examples
  • Interview Questions
  • Interview Questions Asked
  • Java
  • Selenium
  • Manual Testing
  • SQL Tutorial For Beginners
  • Difference
  • Tools
  • Contact Us
  • Search
SoftwareTestingo » Difference » Difference Between TreeMap VS HashMap VS LinkedHashMap In Java

Difference Between TreeMap VS HashMap VS LinkedHashMap In Java

Last Updated on: April 23, 2019 By Softwaretestingo Editorial Board

What We Are Learn On This Post

  • HashMap vs LinkedHashMap vs TreeMap

In this article, we will compare important implementation classes of Map i.e.; HashMap v/s LinkedHashMap v/s TreeMap

Read Also: HashMap vs LinkedHashMap In Java

So lets us discuss in tabular format;

HashMap vs LinkedHashMap vs TreeMap

HashMap
LinkedHashMap
TreeMap
Uses a hash table to store key-value pairs (i.e.; map entries) where duplicate keys are NOT allowed Uses a combination of (hash table + LinkedList) to store key-value pairs (i.e.; map entries) where duplicate keys are NOT allowed Uses the Red-Black tree to store key-value pairs (i.e.; map entries) where duplicate keys are NOT allowed
Insertion order is NOT maintained, as it uses a hashing technique to store key-value pairs (i.e.; map entries) Insertion order is maintained, as it uses the doubly-linked list to store key-value pairs (i.e.; map entries) Insertion order is NOT maintained, as key-value pairs (i.e.; map entries) are stored according to some sorting order
HashMap doesn’t deal with  sorting order; but it can be converted to TreeMap to store key-value pairs (i.e.; map entries) in some sorting orderTreeMap ts = new TreeMap(hashMap); LinkedHashMap doesn’t deal with  sorting order; but it can be converted to TreeMap to store key-value pairs(i.e.; map entries) in some sorting orderTreeMap ts = new TreeMap(linkedHashMap); Keys in TreeMap are sorted, according to some sorting order; it could be either default natural sorting order or programmer-defined customized sorting order
While iterating HashMap, we will get items in random order While iterating LinkedHashMap, we will get items as per insertion order While iterating TreeMap, we will get items in sorted order;  either natural ordering or customized sorting order
This is introduced in the original collection framework in Java 1.2 version This is introduced in Java 1.4 version This is also introduced in the original collection framework in Java 1.2 version
Key: Allows NULL insertion but a maximum of only one NULL value: No upper limit for NULL values against any unique key Key: Allows NULL insertion but a maximum of only one NULL value: No upper limit for NULL values against any unique key Key: From Java 1.7 version, NULL is not allowed to insert;
But with Java version less than 1.6, only as 1st element allowed (for keys)Value: No upper limit for NULL values against any unique key
Check Also: ClassNotFoundException VS NoClassDefFoundError

    Difference Between Verification And Validation in Software Testing
    Difference Between Verification And Validation in Software Testing
    Difference Between Waterfall Vs V Model
    Difference Between Waterfall Vs V Model
    Difference Between
    Difference Between
    Manual Vs Automation
    Manual Vs Automation Testing, Difference & Which Should Use?
    Hashmap vs HashSet In Java
    Difference Between HashMap VS HashSet Java
    BeforeClass & BeforeSuite TestNG Annotation
    Difference Between BeforeClass & BeforeSuite TestNG Annotation
    Difference Between Component and Unit Testing
    Difference Between Component and Unit Testing
    Difference Between Waterfall and Spiral Model
    Difference Between Waterfall and Spiral Model
    Positive and Negative Testing
    Differences Between Positive and Negative Testing in Software Testing
    Difference Between Severity Vs Priority
    Difference Between Severity Vs Priority In Testing

    Filed Under: Difference

    Reader Interactions

    Leave a Reply Cancel reply

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

    Primary Sidebar

    Join SoftwareTestingo Telegram Group

    Categories

    Footer

    Java Tutorial for Beginners | Selenium Tutorial | Manual Testing Tutorial | SQL Tutorial For Beginners | GitHub Tutorial For Beginners | Maven Tutorial

    Copyright © 2023 SoftwareTestingo.com ~ Contact Us ~ Sitemap ~ Privacy Policy ~ Testing Careers