[英]Append a list from a different method type Java
I have two method with two different types and I would like to append the list from the first method to the second method. 我有两种具有两种不同类型的方法,我想将列表从第一种方法追加到第二种方法。 Methods as follows:
方法如下:
private List<Object> mergeData(List<Data1> tabList, List<Data2> tabListAnother){
List<Object> mergeDataList = new ArrayList<Object>();
mergeDataList = ListUtils.union(tabList, tabListAnother);
return mergeDataList;
}
private List<Data1> getData(Some Parameters here........){
List<Data1> data1List = new ArrayList<Data1>();
Some code here adding to list all elements
.......
.......
return data1List;
}
My question is how can I append mergeDataList to data1List so it returns in such a way that it outputs values of mergeDataList and data1List togethor in one return statement? 我的问题是如何将mergeDataList附加到data1List,以便它以一种在返回语句中输出mergeDataList和data1List togethor的值的方式返回?
Help appreciated.. 帮助表示赞赏。
如果我正确地理解了您的问题,则可以只调用getData()
作为一个参数,另一个调用另一个列表的方法。
mergeData(getData(...), otherList)
这很简单,只需执行以下操作:
data1List.addAll(mergeData(tabList,tabListAnother));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.