Multimap Iterator 在 Java 中检索多个值
Multimap Iterator retrieve multiple values in Java
有没有办法在迭代时访问每个值以将其分配给来自 Apache commons 的 java MultiValueMap 的变量?我有一个键和两个可能的值,我想在每次迭代中提取它们,然后将它们写入 table。
目前下面为 pair.getValue() 生成两个值。
public void setValues (MultiValueMap map)
{
Iterator it = map.entrySet().iterator();
while (it.hasNext())
{
Map.Entry pair = (Map.Entry)it.next();
String id = pair.getKey().toString();
String name = pair.getValue().toString();
}
}
为清楚起见,我对此进行了编辑,以下建议有助于使用 Collection values = map.getCollection(id);
如果我理解你的问题,你想获取所有键的值列表:
Iterator it = map.keySet().iterator();
while (it.hasNext())
{
String id = (String)it.next();
Collection<?> values = map.getCollection(id);
// loop on values and do whatever you need ...
}
有没有办法在迭代时访问每个值以将其分配给来自 Apache commons 的 java MultiValueMap 的变量?我有一个键和两个可能的值,我想在每次迭代中提取它们,然后将它们写入 table。
目前下面为 pair.getValue() 生成两个值。
public void setValues (MultiValueMap map)
{
Iterator it = map.entrySet().iterator();
while (it.hasNext())
{
Map.Entry pair = (Map.Entry)it.next();
String id = pair.getKey().toString();
String name = pair.getValue().toString();
}
}
为清楚起见,我对此进行了编辑,以下建议有助于使用 Collection values = map.getCollection(id);
如果我理解你的问题,你想获取所有键的值列表:
Iterator it = map.keySet().iterator();
while (it.hasNext())
{
String id = (String)it.next();
Collection<?> values = map.getCollection(id);
// loop on values and do whatever you need ...
}