码迷,mamicode.com
首页 > 编程语言 > 详细

java实战1

时间:2015-04-21 17:39:42      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

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();
    }
}

 

java实战1

标签:

原文地址:http://www.cnblogs.com/crazyacking/p/4444823.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!