如何合并2 ArrayList <hashmap <string,string =“”>&gt;根据关键值变为1?

时间:2017-11-24 02:45:00

标签: java android arraylist hashmap

我有2 ArrayList < HashMap < String, String>>

  

list1:[{name = Alice,count = 193},{name = Bob,count = 13},{name = Charlie,   count = 179},...]

     

list2:[{name = Alice,change = 1},{name = Bob,change = 15},{name = Jimmy,   change = 15},...]

list2中存在的所有键值都出现在list1中,但反之亦然。例如。由于查理有0变化,他不在list2。我想根据键值(名称)合并这两个列表,以创建一个新的list3

  

list3:[{name = Alice,count = 193,change = 1},{name = Bob,count = 13,   change = 15},{name = Charlie,count = 179,change = 0},...]

2 个答案:

答案 0 :(得分:2)

假设function setResult() { document.getElementById("spanresult").innerHTML= span; document.getElementById("handleresult").innerHTML = innerHandle; document.getElementById("angleresult").innerHTML = bladeAngle; document.getElementById("lengthresult").innerHTML = oarLength; document.getElementById("heightresult").innerHTML = height; document.getElementById("overlayresult").innerHTML = overlay; }; list1不包含重复的list2,您可以执行以下操作:

name

答案 1 :(得分:0)

你可以:

1 /创建一个名为Account的类,其中包含namecountchange,然后结果将是Account的列表(如果您不想创建一个新类,你可以跳过这一步)

2 / list2来自HashMap<String (name), Integer (change)>

3 /遍历list1,其中每个元素在步骤2中构建的change上找到相应的HashMap基础,然后构建Account(或HashMap包含所有信息),将帐户(或HashMap)添加到list3