Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 941067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:03:33+00:00 2026-05-15T22:03:33+00:00

Is there a map like data structure with integer as key , string as

  • 0

Is there a map like data structure with integer as key , string as value, which ends up to be sorted by key no matter on insertion order like when you insert first item {4, somevalue} that it will be on the fourth place when you use it in further application flow

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:03:34+00:00Added an answer on May 15, 2026 at 10:03 pm

    The interface SortedMap<K,V> defines a type that has the behavior you’re looking for:

    A Map that further provides a total ordering on its keys. The map is ordered according to the natural ordering of its keys, or by a Comparator typically provided at sorted map creation time. This order is reflected when iterating over the sorted map’s collection views (returned by the entrySet, keySet and values methods).

    A particular implementation of a SortedMap that may be of interest is a TreeMap:

    A Red-Black tree based NavigableMap implementation. The map is sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time, depending on which constructor is used.

    This implementation provides guaranteed log(n) time cost for the containsKey, get, put and remove operations.

    Note that interface NavigableMap<K,V> extends SortedMap<K,V>. That is, a NavigableMap is a SortedMap, but it also specifies additional methods, e.g. all-inclusive bounds subMap. If you don’t need these additional functionarlities, simply a SortedMap should work just fine.

    See also

    • Java Tutorials/Collections

    Example

    This shows basic usage of NavigableSet<K,V>:

        NavigableMap<Integer,String> nmap =
            new TreeMap<Integer,String>();
        
        nmap.put(3, "Three");
        nmap.put(1, "One");
        nmap.put(4, "Four");
        nmap.put(5, "Five");
        nmap.put(7, "Seven");
        
        System.out.println(nmap);
        // {1=One, 3=Three, 4=Four, 5=Five, 7=Seven}
    
        System.out.println(nmap.firstKey()); // 1
        System.out.println(nmap.lastEntry().getValue()); // Seven
        System.out.println(nmap.higherKey(1)); // 3 
        System.out.println(nmap.lowerEntry(6).getValue()); // Five
    
        NavigableMap<Integer,String> sub = nmap.subMap(2, true, 5, true);
        for (Map.Entry<Integer,String> entry : sub.entrySet()) {
            System.out.printf("%s => %s%n",
                entry.getKey(),
                entry.getValue()
            );
        }
        // 3 => Three
        // 4 => Four
        // 5 => Five
    

    Related questions

    On basic Map manipulation:

    • Iterate Over Map
    • iterating over and removing from a map

    Others of interest:

    • Why doesn’t Java Map extends Collection?

    On SortedMap vs NavigableMap:

    • How to do inclusive range queries when only half-open range is supported (ala SortedMap.subMap)
    • Writing a synchronized thread-safety wrapper for NavigableMap
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 502k
  • Answers 502k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In short: Yes. Go with the first example... The hash… May 16, 2026 at 2:40 pm
  • Editorial Team
    Editorial Team added an answer From the received comments, I must conclude that the error… May 16, 2026 at 2:40 pm
  • Editorial Team
    Editorial Team added an answer Something like this ? DateTime[] dateTimes = new[] { new… May 16, 2026 at 2:40 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I would like to store a mapping of an integer key to a float
I am looking for a data structure that operates similar to a hash table,
Here's a description: It operates like a regular map with get , put ,
Is there something like a two sided list in Java? Maybe a third party
Is there a way to export table data to a MIME Resource (Flex3 component)
I have a special list (a sort of queue, as in the data structure,
What I would like to do (in C++) is create a 'Parameter' data type
i am generating a chart map like this: http://chart.apis.google.com/chart?chs=440x220&cht=t&chco=CBD122&chld=US&chd=s:_&chtm=usa does anyone know if there
I call an XML document three-layered if its structure is laid out as following:
I have to map a set of known integers to another set of known

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.