English 中文(简体)
从储存在海 Java地图的清单中增加新清单的数值
原标题:trouble adding values to a new List from a list stored in a hashmap - Java

我一直在追捕他们,以便这样做。

我想要做的是:

我有:

qualifiedCompetitors = new HashMap<String, List<String>>();

分配到散列图的数值是:

String[] events = {"Helicopter", "Amphibious", 
                     "4x4", "Fire Engine"};

String[][] competitors = 
{
   {"Greg", "Will", "Fleur", "Bill", "Bella", "Sally", "Olive", "Sal", "Dora", "Chas"}, 
   {"Yuri", "Abe", "Tim", "Fleur", "Bonnie", "Vera", "Ed", "Dan", "Jill", "Rose", "Zoe"}, 
   {"Tim", "Fleur", "Will",  "Bill", "Bella", "Dan", "Jill", "Rose", "Greg",  "Abe", "Sally", "Yuri", "Olive", "Sal", "Jim"}, 
   {"Jill", "Rose", "Greg", "Abe", "Bonnie", "Vera", "Ed", "Zoe", "Ben", "Freda", "Chuck", "Fred"}
};

关键筛选是事件的名称,清单是竞争者名单。 我想建立一个所有竞争者的新名单。

因此,我尝试了诸如:

ListOfAllqualifiedCompetitors = new ArrayList(qualifiedCompetitors.values());

接着通过散列图进行:

Collection allCompetitors = qualifiedCompetitors.values();

System.out.println("Values of Collection created from Hashtable are :");
//iterate through the collection
Iterator itr = allDrivers.iterator();
while(itr.hasNext())
  System.out.println(itr.next());

看到我拿到什么东西,什么是罚款,但我不能再增加一个新名单? 我知道我没有什么明显的建议?

最佳回答

我的think <>/em>请你再说的是,你有一张<编码>String/code>至List<String>,你想积累所有<代码>。 清单和编号;String> 列入一个较长的清单。 如果是:

final Map<String, List<String>> eventsToCompetitors;
final List<String> allCompetitors;

eventsToCompetitors = ...

allCompetitors = new ArrayList<String>();
for (Collection<String> competitors : eventsToCompetitors.values())
{
  allCompetitors.addAll(competitors);
}
问题回答
List<String> allCompetitors = new ArrayList<String>();
for(Set<String> competitors : qualifiedCompetitors.values()) {
    allCompetitors.addAll(competitors);
}

你们指的是什么?





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签