Packagecollection;Importjava.util.ArrayList;Importjava.util.List;ImportOrg.apache.log4j.Logger;Importorg.junit.Test;/*** <p> @ClassName: collectiontest01</p>* <p>description:java Collection </p>*/ Public classCollectionTest01 {Private StaticLogger Logger = Logger.getlogger (CollectionTest01.class); @Test Public voidtest01 () {List<String> List1 =NewArraylist<string>(); List<String> List2 =NewArraylist<string>(); List1.add ("123"); List1.add ("1234"); List1.add ("12345"); List1.add ("12354"); List1.add ("123456"); List1.add ("123457"); List2.add ("1231"); List2.add ("1234"); List2.add ("12345"); List2.add ("12354"); List2.add ("12346"); List2.add ("123458"); //1. Append the elements in the List2 to the List1, AddAll ()//List1.addall (LIST2); //2, remove from List1, List1 and list2 the same elements, RemoveAll ()//List1.removeall (LIST2); //3, remove from List1, List1 and List2 different elements (for the intersection of two sets), Retainall ()//List1.retainall (LIST2); //4. Does the list1 contain all the elements in the List2 Booleanb =List1.containsall (LIST2); Logger.info (b); Logger.info (List1); } }
Java Collection Framework Collection