// public static void main(String[] args) {
// List<Map<String, String>> list2 = new ArrayList<Map<String,String>>();
// List<Map<String, String>> list3 = new ArrayList<Map<String,String>>();
// Map<String, String> map1=new HashMap();
// Map<String, String> map2=new HashMap();
// map1.put("1", "1");
// map1.put("2", "11");
// map1.put("3", "111");
// map2.put("1", "2");
// map2.put("2", "22");
// map2.put("3", "222");
// map2.put("4", "2222");
// map2.put("5", "22222");
// list2.add(map1);
// list3.add(map2);
// list2.addAll(list3);
// }

注意 list.addAll方法返回的是boolean值

 

 

java 两条sql 从两个不同的数据库,查出两个格式相同的数据集合,把他们合并在一起分页

这种情况推荐使用guava(google出品的哦),为了简洁,只放核心代码,让你瞬间有思路:

合并:

List<String> list1 = Arrays.asList("1","2","3","4","5","6","7");
List<String> list2 = Arrays.asList("2","3","4","5","6","7","8");
List<String> list = Lists.newArrayList(list1, list2);

分页:

List<String> list = Arrays.asList("1","2","3","4","5","6","7");
List<List<String>> partition = ListUtils.partition(list, 2);//分页数量

拓展-- 交差并集(可能对你有帮助):

public static void main(String[] args) {
    Set<Integer> sets = Sets.newHashSet(1, 2, 3, 4, 5, 6);
    Set<Integer> sets2 = Sets.newHashSet(3, 4, 5, 6, 7, 8, 9);
    // 交集
    System.out.println("交集为:");
    SetView<Integer> intersection = Sets.intersection(sets, sets2);
    for (Integer temp : intersection) {
        System.out.println(temp);
    }
    // 差集
    System.out.println("差集为:");
    SetView<Integer> diff = Sets.difference(sets, sets2);
    for (Integer temp : diff) {
        System.out.println(temp);
    }
    // 并集
    System.out.println("并集为:");
    SetView<Integer> union = Sets.union(sets, sets2);
    for (Integer temp : union) {
        System.out.println(temp);
    }
}