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 1017159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:39:40+00:00 2026-05-16T10:39:40+00:00

I need to convert a navigable map to a 2D String array. Below given

  • 0

I need to convert a navigable map to a 2D String array. Below given is a code from an answer to one of my previous question.

NavigableMap<Integer,String> map =
        new TreeMap<Integer, String>();

map.put(0, "Kids");
map.put(11, "Teens");
map.put(20, "Twenties");
map.put(30, "Thirties");
map.put(40, "Forties");
map.put(50, "Senior");
map.put(100, "OMG OMG OMG!");

System.out.println(map.get(map.floorKey(13)));     // Teens
System.out.println(map.get(map.floorKey(29)));     // Twenties
System.out.println(map.get(map.floorKey(30)));     // Thirties
System.out.println(map.floorEntry(42).getValue()); // Forties
System.out.println(map.get(map.floorKey(666)));    // OMG OMG OMG!

I have to convert this map to a 2D String array:

{
{"0-11","Kids"},
{"11-20","Teens"},
{"20-30","Twenties"}
...
}

Is there a fast and elegant way to do this?

  • 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-16T10:39:41+00:00Added an answer on May 16, 2026 at 10:39 am

    Best bet is just to iterate through the Map and create an array for each entry, the troublesome part is generating things like “0-11” since this requires looking for the next highest key…but since the Map is sorted (because you’re using a TreeMap) it’s no big deal.

    String[][] strArr = new String[map.size()][2];
    int i = 0;
    for(Entry<Integer, String> entry : map.entrySet()){
        // current key
        Integer key = entry.getKey();
        // next key, or null if there isn't one
        Integer nextKey = map.higherKey(key);
    
        // you might want to define some behavior for when nextKey is null
    
        // build the "0-11" part (column 0)
        strArr[i][0] = key + "-" + nextKey;
    
        // add the "Teens" part (this is just the value from the Map Entry)
        strArr[i][1] = entry.getValue();
    
        // increment i for the next row in strArr
        i++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer EF1 is not that much different on the code side… May 16, 2026 at 5:28 pm
  • Editorial Team
    Editorial Team added an answer Using Unicode, there is more than one valid way to… May 16, 2026 at 5:28 pm
  • Editorial Team
    Editorial Team added an answer You need to add the (JAR-relative) path to the XML… May 16, 2026 at 5:28 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 need to convert the text in the textbox of my xaml code to
I need to convert a string like this: A &#039;quote&#039; is <b>bold</b> into: A
I need to convert an integer into a base64-character representation. I'm using OxA3's answer
I need to convert a String representation of a nested List back to a
I need to convert a date from this format: 2002-10-10T12:00:00-05:00 (xs:dateTime as defined in
I need to convert string name1, b, 2, name2, c, 3, name3, b, 2,
How can I convert a string to a regular expression that matches itself in
I have a field varchar(14) = 20090226115644 I need convert it to -> 2009-02-26
hey, i have this path name from an input element interesse[angebote][flurfuerderfahrzeuge] as a string
I need to convert a SimpleXML object to a DOMDocument , to use it

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.