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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:45:30+00:00 2026-06-06T09:45:30+00:00

Map<String, List<String>> words = new HashMap<String, List<String>>(); List<Map> listOfHash = new ArrayList<Map>(); for (int

  • 0
Map<String, List<String>> words = new HashMap<String, List<String>>();
            List<Map> listOfHash = new ArrayList<Map>();

            for (int temp = 0; temp < nList.getLength(); temp++) {
                Node nNode = nList.item(temp);
                if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                    Element eElement = (Element) nNode;
                    String word = getTagValue("word", eElement);
                    List<String> add_word = new ArrayList<String>();
                    String pos = getTagValue("POS", eElement);
                    if(words.get(pos)!=null){
                        add_word.addAll(words.get(pos));
                        add_word.add(word);
                    }
                    else{
                        add_word.add(word);
                    }
                    words.put(pos, add_word);
                }
            }

This is a segment of code I have written (it uses Stanford CoreNLP). The problem I am facing is that presently this code is working only with one Map i.e. “words”. Now, I want that as soon as the parser sees “000000000” which is my delimiter, then a new Map should be added to the List and then the keys and values to be inserted into it. If it does not see “000000000”, then the Keys and Values are to be added in the same Map.
Please help me with that as I am not able to do it even after a lot of efforts.

  • 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-06T09:45:41+00:00Added an answer on June 6, 2026 at 9:45 am

    I guess listOfHash is to contain all your Maps…

    So rename words to currentMap for example and add to it. When you see “000000000” instantiate a new Map, assign it to currentMap, add it to the list and go on…

    something like:

    if ("000000000".equals(word)){
        currentMap = new HashMap<String, List<String>>();
        listOfHash.add(currentMap);
        continue; // if we wan't to skip the insertion of "000000000"
    }
    

    And don’t forget to add your initial Map to listOfHash.

    I also see you have other problems with your code, here is modified version (I have not tried to compile it):

    Map<String, List<String>> currentMap = new HashMap<String, List<String>>();
    List<Map> listOfHash = new ArrayList<Map>();
    listOfHash.add(currentMap);
    
    
    for (int temp = 0; temp < nList.getLength(); temp++) {
        Node nNode = nList.item(temp);
        if (nNode.getNodeType() == Node.ELEMENT_NODE) {
            Element eElement = (Element) nNode;
            String word = getTagValue("word", eElement);    
    
            if ("000000000".equals(word)){
                currentMap = new HashMap<String, List<String>>();
                listOfHash.add(currentMap);
                continue; // if we wan't to skip the insertion of "000000000"
            }
    
            String pos = getTagValue("POS", eElement);
    
            List<String> add_word = currentMap.get(pos);
            if(add_word==null){
                add_word = new ArrayList<String>();
                currentMap.put(pos, add_word);
            }
            add_word.add(word);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can somebody explain me why this Map<String, List<String>> foo = new HashMap<String, LinkedList<String>>(); generates
I have an unordered map: class O(val a: Int) Map[String, List[O]] which I'd like
I have a map<string, list<int> > which I want to iterate over the list
I have a property @JsonProperty private Map<String, String> parameters = new HashMap<String, String>(); When
In my java coding, I often end up with several Map<String,Map<String,foo>> or Map<String,List<String>> and
Is there any difference between List<Map<String, String>> and List<? extends Map<String, String>> ? If
I have a map declared as follows: map < string , list < string
If i have a stl map from string to int and i want to
Im using the following structure: hash_map<string, list<time_t>> When I initially fill the hash map
I have the following map extension object ImplicitMap { implicit def extendMap(m : Map[String,Any])

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.