如何在java中将两个对象列表连接成一个

use*_*187 0 java

嗨我有两个对象的ArrayList,我需要将它合并为一个列表.这是我的要求

我的第一个列表

利斯塔

{StaffFirstName=f2, resourceId=2, totalcost=18055.0, totalPercentageInvolvment=550, ResourceCost=2300, staffRole=tl}
Run Code Online (Sandbox Code Playgroud)

和listB

{sixthmonth=60, fourthmonth=40, firstmonth=10, fifthmonth=50, secondmonth=20, `thirdmonth=30}`
Run Code Online (Sandbox Code Playgroud)

我需要结果

结果

{StaffFirstName=f2, resourceId=2, totalcost=18055.0, totalPercentageInvolvment=550, ResourceCost=2300, staffRole=tl, sixthmonth=60, fourthmonth=40, firstmonth=10, fifthmonth=50, secondmonth=20, thirdmonth=30}
Run Code Online (Sandbox Code Playgroud)

编辑!

实际上我的两个列表都是arrayList所以我的listA将是

{StaffFirstName=f2, resourceId=2, totalcost=18055.0, totalPercentageInvolvment=550, ResourceCost=2300, staffRole=tl}
{StaffFirstName=demo35, resourceId=3, totalcost=19625.0, totalPercentageInvolvment=785, ResourceCost=2500, staffRole=sweeper}
Run Code Online (Sandbox Code Playgroud)

列表B将是

{sixthmonth=100, fourthmonth=30, firstmonth=40, fifthmonth=25, secondmonth=100, thirdmonth=90}
{sixthmonth=100, fourthmonth=30, firstmonth=40, fifthmonth=25, secondmonth=100, thirdmonth=90}
Run Code Online (Sandbox Code Playgroud)

结果应该是

{StaffFirstName=f2, resourceId=2, totalcost=18055.0, totalPercentageInvolvment=550, ResourceCost=2300, staffRole=tl, sixthmonth=60, fourthmonth=40, firstmonth=10, fifthmonth=50, secondmonth=20, thirdmonth=30}
{StaffFirstName=demo35, resourceId=3, totalcost=19625.0, totalPercentageInvolvment=785, ResourceCost=2500, staffRole=sweeper, sixthmonth=100, fourthmonth=30, firstmonth=40, fifthmonth=25, secondmonth=100, thirdmonth=90}
Run Code Online (Sandbox Code Playgroud)

这意味着我的两个列表中的每一行都必须明智地追加我的行.如果我使用addAll函数,那么两个列表就像这样追加

{StaffFirstName=f2, resourceId=2, totalcost=18055.0, totalPercentageInvolvment=550, ResourceCost=2300, staffRole=tl}
{StaffFirstName=demo35, resourceId=3, totalcost=19625.0, totalPercentageInvolvment=785, ResourceCost=2500, staffRole=sweeper}
{sixthmonth=60, fourthmonth=40, firstmonth=10, fifthmonth=50, secondmonth=20, thirdmonth=30}
{sixthmonth=100, fourthmonth=30, firstmonth=40, fifthmonth=25, secondmonth=100, thirdmonth=90}. But i need to append the two list row wise. Is it possible?
Run Code Online (Sandbox Code Playgroud)

And*_*mas 5

鉴于:

   List<MyClass> listA, listB;
Run Code Online (Sandbox Code Playgroud)

试试这个:

   List<MyClass> union = new ArrayList<MyClass>();
   union.addAll( listA );
   union.addAll( listB );
Run Code Online (Sandbox Code Playgroud)