Create hasmaps recursively in Java

I'm trying to create a new HashMap for each document I enter In pseudocode, I can think of something similar:

For(eachInputDoc)
{
    Map<String,String> mapInputNumber = new HashMap<String,String>;
}

Then for the four files, you will have:

mapInput1
mapInput2
mapInput3
mapInput4

How can I do that?

Solution

It looks like you're trying to declare variables dynamically You can't do this in Java - the variables themselves are determined at compile time However, you can create a list:

List<Map<String,String>> maps = new ArrayList<Map<String,String>>();
for (Document doc : docs)
{
    Map<String,String> map = new HashMap<String,String>();
    // Populate map from doc
    maps.add(map);
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>