【问题标题】:Can two lists into one list if they have different parameters?如果两个列表具有不同的参数,它们可以合并为一个列表吗?
【发布时间】:2022-06-17 14:59:12
【问题描述】:
classA a = new classA (int age, String race , String country);
classB b = new classB(String day,String month, String year);
List<classA> listA = new ArrayList<>();
listA.add(a);
List<classB> listB = new ArrayList<>();
listB.add(b);
List<Base> combinedList = new ArrayList<>();
combinedList.addAll(listA);
combinedList.addAll(ListB);

另一个例子

classA a = new classA (int width, int height);
classB b = new classB(in far, int near, String time);
List<classA> listA = new ArrayList<>();
listA.add(a);
List<classB> listB = new ArrayList<>();
listB.add(b);
List<Base> combinedList = new ArrayList<>();
combinedList.addAll(listA);
combinedList.addAll(ListB);

在哪个示例中添加列表是可能的?我的主要问题是关于添加两个具有不同数量参数的列表来制作一个列表。这可能吗?

【问题讨论】:

  • classA 和 classB 是扩展还是实现 Base?

标签: java android list arraylist


猜你喜欢
  • 1970-01-01
  • 2023-04-03
  • 1970-01-01
  • 2019-01-18
  • 1970-01-01
  • 2018-03-18
  • 1970-01-01
  • 1970-01-01
  • 2020-07-11
相关资源
最近更新 更多