boolean retainAll(Collection c) 
          Retains only the elements in this collection that are contained in the specified collection (optional operation).

解决方案 »

  1.   

    那只能用程序算法实现了,定义一个新的集合c,便利a集合中的每一个元素,如果这个元素在b集合中存在就将他写入c集合。
      

  2.   

    ArrayList al1 = new ArrayList();
                al1.add("abc");
                al1.add("abc2");
                al1.add("abc3");            ArrayList al2 = new ArrayList();
                al2.add("abc");
                al2.add("asdfd");            al1.retainAll(al2);
                for(int i=0;i<al1.size();i++)
                    System.out.println(al1.get(i));Print out abc
      

  3.   

    Override the equals,hashcode method,if the containner hold the object.