我创造了一个类似的情况来测试你在说什么。显然我无权访问您的特定数据库进行查询,所以我只关注您的问题;List
组合。
List<String> foods = new ArrayList<String>(); //this is analogous with the list returned from your first query
foods.add("Beef");
foods.add("Chicken");
System.out.println("foods(query1): "+foods);
List<String> fruits = new ArrayList<String>(); //this is analogous with the list returned from your second query
fruits.add("Apple");
fruits.add("Peach");
fruits.add("Pear");
System.out.println("fruits(query2): "+fruits);
foods.addAll(fruits); //this combines the two lists (your two queries)
System.out.println("foods(after combination of queries): "+foods);
输出是:
foods(query1): [Beef, Chicken]
fruits(query2): [Apple, Peach, Pear]
foods(after combination of queries): [Beef, Chicken, Apple, Peach, Pear]
关于为什么你没有得到这个结果,我唯一的想法是你的一个查询没有返回任何东西......我建议在将它们添加在一起之前尝试打印出每个列表,就像我上面所做的那样,看看一个是否为空.