Java 如何从linkedhashmaps列表中单独获取linkedhashmap
我有一个地图列表,从中我需要每个地图单独用于进一步的目的。下面是我正在使用的代码片段Java 如何从linkedhashmaps列表中单独获取linkedhashmap,java,list,maps,Java,List,Maps,我有一个地图列表,从中我需要每个地图单独用于进一步的目的。下面是我正在使用的代码片段 for(int i = 0; i < 5; i++) { listOfMaps.add(new LinkedHashMap<String, Double>()); } int j=0; while(it.hasNext()) { try { List<Entry<String,
for(int i = 0; i < 5; i++) {
listOfMaps.add(new LinkedHashMap<String, Double>());
}
int j=0;
while(it.hasNext())
{
try
{
List<Entry<String,Double>> list1 = new ArrayList<Entry<String,Double>>();
Map.Entry pairs = (Map.Entry)it.next();
System.out.println( pairs.getKey() );
for (int i = 0; i< ((List<Entry<String, Double>>) pairs.getValue()).size() ; i++)
{
String docId = ((List<Entry<String, Double>>) pairs.getValue()).get(i).getKey();
Double ScoreValue = ((List<Entry<String, Double>>) pairs.getValue()).get(i).getValue();
listOfMaps.get(j).put(docId, ScoreValue);
}
for(int i=0;i<5;i++){
添加(新LinkedHashMap());
}
int j=0;
while(it.hasNext())
{
尝试
{
List list1=新的ArrayList();
Map.Entry pairs=(Map.Entry)it.next();
System.out.println(pairs.getKey());
对于(int i=0;i<((列表)pairs.getValue()).size();i++)
{
字符串docId=((列表)pairs.getValue()).get(i.getKey();
Double ScoreValue=((列表)pairs.getValue()).get(i.getValue();
listofmap.get(j).put(docId,ScoreValue);
}
如何分别处理它们,我还想确保每个地图的大小相同。如何确保列表中的所有地图大小相同。这是一个小程序,我为您编写的 我不明白流程逻辑,那就是你想如何处理地图 所以我创建了一个单独的process函数,这样就可以在其中插入逻辑
static List<Map<String, Double>> listOfMaps = new ArrayList<Map<String, Double>>();
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
Map map=new LinkedHashMap<String, Double>();
map.put("serial",i);
putValues(map);
listOfMaps.add(map);
}
int j = 0;
Iterator<Map<String, Double>> it = listOfMaps.iterator();
while (it.hasNext()) {
Map mapItem = (LinkedHashMap) it.next();
process(mapItem);
System.out.println("After processing"+mapItem);
/*System.out.println(pairs.getKey());
for (int i = 0; i < ((List<Entry<String, Double>>) pairs.getValue())
.size(); i++) {
String docId = ((List<Entry<String, Double>>) pairs.getValue())
.get(i).getKey();
Double ScoreValue = ((List<Entry<String, Double>>) pairs
.getValue()).get(i).getValue();
listOfMaps.get(j).put(docId, ScoreValue);
}*/
}
静态列表listofmap=newarraylist();
公共静态void main(字符串[]args){
对于(int i=0;i<5;i++){
Map Map=newlinkedhashmap();
地图("连载",i);;
putValues(map);
添加(映射);
}
int j=0;
迭代器it=listOfMaps.Iterator();
while(it.hasNext()){
Map mapItem=(LinkedHashMap)it.next();
过程(mapItem);
System.out.println(“处理后”+mapItem);
/*System.out.println(pairs.getKey());
对于(int i=0;i<((List)pairs.getValue())
.size();i++){
字符串docId=((列表)pairs.getValue())
.get(i.getKey();
Double ScoreValue=((列表)对
.getValue()).get(i.getValue();
listofmap.get(j).put(docId,ScoreValue);
}*/
}