java合并list

import java.util.ArrayList;
import java.util.List;
 
import com.google.common.collect.Lists;
 
private static void across() {
  String ids1 = "1,2,3,4";
  String ids2 = "3,4,5";
  String ids3 = "6,7,1";
  String[] temp1 = ids1.split(",");
  String[] temp2 = ids2.split(",");
  String[] temp3 = ids3.split(",");
  List<String> list1 = Lists.newArrayList(temp1);
  List<String> list2 = Lists.newArrayList(temp2);
  List<String> list3 = Lists.newArrayList(temp3);
  list1.removeAll(list2);
  list1.addAll(list2);
  list1.removeAll(list3);
  list1.addAll(list3);
  printStr(list1);
 }
 
Arrays.asList也能将数组装换为List,但返回的List大小已经固定,不支持removeAll,addAll。

posted on 2014-04-10 00:43  sangbiao  阅读(291)  评论(0编辑  收藏  举报