Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

treemap vs linkedhashmap

Pragya Keshap answered on February 28, 2023 Popularity 8/10 Helpfulness 1/10

Contents


More Related Answers

  • Implementation of LinkedHashMap Class in Java map
  • linkedhashmap in java
  • What are the differences between a HashMap and a TreeMap?
  • treemap vs hashmap
  • What are the main differences between HashMap and ConcurrentHashMap in Java?
  • Java Creating LinkedHashMap from Other Maps
  • linkedhashmap vs linkedhashset
  • When to use HashMap or TreeMap?
  • difference between LinkedHashMap and LinkedHashSet
  • difference between hashmap and linkedhashmap

  • treemap vs linkedhashmap

    -1

    TreeMap and LinkedHashMap are both implementations of the Map interface in Java, but they differ in the way they store and retrieve the key-value pairs.

    TreeMap is a sorted map implementation that uses a red-black tree to store the keys in a sorted order. The keys must implement the Comparable interface, or an external Comparator must be provided. As a result, TreeMap provides guaranteed log(n) time cost for the containsKey, get, put, and remove operations. The drawback of TreeMap is that it does not maintain the insertion order of the keys.

    Each entry in a LinkedHashMap maintains a pointer to the entry that comes before it and the entry that comes after it, which allows the entries to be ordered based on their insertion order or the order in which they were last accessed. The iteration order of the entries in a LinkedHashMap is determined by the order in which they were inserted or the order in which they were last accessed, depending on the constructor used to create the LinkedHashMap.  

    Popularity 8/10 Helpfulness 1/10 Language whatever
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on Feb 28 2023
    Pragya Keshap
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.