JAVA线性表(删除/合并操作)

package basic.day12;

import java.util.ArrayList;


public class ArrayListDemo3 {
    public static void main(String[] args) {
        ArrayList list = new ArrayList();
        list.add(1);
        list.add(2);
        ArrayList other = new ArrayList();
        other.add(2);
        other.add(3);
        list.addAll(other); // 合并两个线性表
        System.out.println(list); // [1, 2, 2, 3]
        list.remove(0);//删除下标为0的值(1)

        System.out.println(list);//[2, 2, 3]
        list.removeAll(other);// 删除了2,2,3
        System.out.println(list); 
        list.retainAll(other);
        System.out.println(list);

   }
}

 

posted @ 2013-06-22 23:49  墨迹哥's  阅读(573)  评论(0编辑  收藏  举报