标签:
import java.io.BufferedInputStream; import java.io.PrintStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner cin=new Scanner(new BufferedInputStream(System.in)); Collection<String> Arr =new ArrayList<String> (Arrays.asList("A","B","C","D","E","F")); String[] strArray ={"G","H","I","J","K"}; Arr.addAll(Arrays.asList(strArray)); Collections.addAll(Arr,"M","N"); final PrintStream cout=System.out; cout.println(Arr); // 迭代容器中的每一个元素 Iterator it=Arr.iterator(); for(;it.hasNext();) { cout.print(it.next()+" "); } cout.println(""); for(String i:Arr) { cout.print(i+" "); } cout.println(""); Arr.remove("A"); for(String i:Arr) { cout.print(i+" "); } cout.println(""); Collection<String> Arr2=new ArrayList<String>( Arrays.asList("B","C","D","E")); Arr.retainAll(Arr2); for(String i:Arr) { cout.print(i+ " "); } cout.println(""); Object[] o=Arr.toArray(); cout.print(Arrays.deepToString(o)); cout.println(""); Arr.removeAll(Arr); cout.println(Arr.size()+" "); cout.println(); } }
标签:
原文地址:http://www.cnblogs.com/crazyacking/p/4444823.html