我一直在寻找一种方法来做到这一点,这让我发疯!
我正在尝试做的事情如下:
我有一个HashMap:
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"}
};
关键是事件的名称,而 List 是竞争对手的列表。我想建立一个所有竞争对手的新列表。
因此,我尝试了各种方法,例如:
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());
看看我得到了什么值,这很好,但我不能再给它们添加一个新列表?我知道我遗漏了一些明显的建议?