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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:49:26+00:00 2026-06-04T08:49:26+00:00

I have values coming from map like the following Key = 1_1, Value =

  • 0

I have values coming from map like the following

Key = 1_1, Value = 02/04/2012
Key = 1_2, Value = 03/04/2012
Key = 1_3, Value = 04/04/2012
Key = 1_4, Value = 05/04/2012
Key = 1_5, Value = 06/04/2012
Key = 1_6, Value = 09/04/2012
Key = 1_7, Value = 10/04/2012
Key = 1_8, Value = 11/04/2012
Key = 1_9, Value = 12/04/2012
Key = 1_10, Value = 13/04/2012
Key = 1_11, Value = 18/04/2012
Key = 1_12, Value = 19/04/2012
Key = 1_13, Value = 20/04/2012
Key = 1_14, Value = 23/04/2012
Key = 1_15, Value = 24/04/2012
Key = 1_16, Value = 25/04/2012
Key = 1_17, Value = 26/04/2012
Key = 1_18, Value = 27/04/2012
Key = 1_19, Value = 30/04/2012
Key = 10_20, Value = 02/04/2012
Key = 10_21, Value = 03/04/2012
Key = 10_22, Value = 04/04/2012
Key = 10_23, Value = 05/04/2012
Key = 10_24, Value = 06/04/2012
Key = 10_25, Value = 09/04/2012
Key = 10_26, Value = 10/04/2012
Key = 10_27, Value = 11/04/2012
Key = 10_28, Value = 12/04/2012
Key = 10_29, Value = 13/04/2012
Key = 10_30, Value = 16/04/2012
Key = 10_31, Value = 17/04/2012
Key = 10_32, Value = 18/04/2012
Key = 10_33, Value = 19/04/2012
Key = 10_34, Value = 23/04/2012
Key = 10_35, Value = 24/04/2012
Key = 10_36, Value = 26/04/2012
Key = 10_37, Value = 27/04/2012

I am really struggling to separate these values and put them in separate map.

i would like to group as follows.

1_1 to 1_19 this i want to split based on “_” and get the first value alone and group them in to a separate map.

like 1 is key and the value will be the date.

EDIT:

employeeMap =  showExelData(sheetData);
        String previousEemployeeID = "",employeeID[];
        Iterator<Map.Entry> entries = employeeMap.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry entry = entries.next();
            employeeID = entry.getKey().toString().split("_");

                // this is the place where i want to check the values if 1 than group the values it can be even  Key = 1_0, Value = 25/04/2012 to  If Key = 1_18, Value = 30/04/2012
     but when the other one comes ex :  Key = 10_0, Value = 25/04/2012 to  If Key = 10_17, Value = 30/04/2012it has to go to new Map 

this is the place where i am lacking.
}

  • 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-06-04T08:49:29+00:00Added an answer on June 4, 2026 at 8:49 am

    If you want to split 1_1, 1_2 up to 1_19.. use the split() function of the String class.

    Ex.

    String x = 1_19;
    
    String[] y = x.split("_");
    

    y[0] would be equal to 1 and y[1] would be 19

    As for using the first value for a key in a map, that would not be possible because it requires a unique key for every entry in the map just like what npinti commented on your post.

    public class Mapping {
    
        Map<String, String> coMap;
        List<String> coList;
    
        public Mapping() 
        {
            init();
        }
    
        public static void main(String[] args) 
        {
            Mapping oMapping = new Mapping();
    
            Map<String, Map<String, String>> oMap = oMapping.classifyMapEntries();
    
            for ( String sParentKey : oMapping.coList )
            {
                Map<String, String> oChildMap = oMap.get(sParentKey);
                Iterator<String> oIterator = oChildMap.keySet().iterator();
    
                System.out.println("Map");
                while( oIterator.hasNext() )
                {
                    String sChildKey = oIterator.next();
                    System.out.print( "Key: " + sChildKey + ", Value: " 
                                        + oChildMap.get(sChildKey) + "\n");
                }
            }
        }
    
        private void init()
        {
            coMap = new HashMap<String, String>();
            coList = new ArrayList<String>();
    
            coMap.put("1_1", "a");
            coMap.put("1_19", "a");
            coMap.put("10_1", "b");
            coMap.put("10_19", "b");
        }
    
        private Map<String, Map<String, String>> classifyMapEntries()
        {
            Map<String, Map<String, String>> oClassified = 
                new HashMap<String, Map<String,String>>();
    
            Iterator<String> oIterator = coMap.keySet().iterator();
            while( oIterator.hasNext() )
            {
                String sKey = oIterator.next();
    
                String sFirst = sKey.substring(0,sKey.indexOf("_"));
                if ( !coList.contains(sFirst) )
                {
                    coList.add(sFirst);
                }
            }
    
            for ( String sKey : coList )
            {
                Map<String, String> oChildMap = new HashMap<String, String>();
    
                Iterator<String> oIterator2 = coMap.keySet().iterator();
                while( oIterator2.hasNext() )
                {
                    String sChildKey = oIterator2.next();
                    String sParentKey = sChildKey.substring(0,sChildKey.indexOf("_"));
    
                    if ( sKey.equals(sParentKey) )
                    {
                        oChildMap.put(sChildKey, coMap.get(sChildKey));
                    }
                }
    
                oClassified.put(sKey, oChildMap);
            }
    
            return oClassified;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have color values coming from the url data is like this, #ff33cc. How
I have a string value coming from a label in the .aspx page as
I have a UTC DateTime value coming from a database record. I also have
My code did the following: Retrieve a value from a map with operator[] .
I have some values coming from a datasource that I have control over. I
Consider the scenario I have values assigned like these Amazon -1 Walmart -2 Target
I have some values in a configuration file (XML file) with some values like
Coming from NHibernate, I've tried to do something like this in Java (first example):
In my application, I have URN-identified data coming in from the server. I'm in
Im an Android noob, coming from objC, I have a very stupid question (project

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.