美文网首页
AddAllCollection

AddAllCollection

作者: 勇者与王者 | 来源:发表于2019-09-26 14:51 被阅读0次

package collectionDemo;

import java.util.ArrayList;

/**
* 
* @author q06285:
* @version 创建时间:2019年9月26日 下午2:39:41
* 
*/
public class AddAllCollection {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        ArrayList<Hero> heros = new ArrayList<>();
        
        for (int i = 0;i < 5;i++) {
            heros.add(new Hero("hero "+i));
        }
        
        System.out.println("ArrayList heros: \t"+heros);
        
        ArrayList<Hero> anotherHeros = new ArrayList<>();
        anotherHeros.add(new Hero("Hero a"));
        anotherHeros.add(new Hero("Hero b"));
        anotherHeros.add(new Hero("Hero c"));
        System.out.println("anotherHeros heros: \t"+anotherHeros);
        
        heros.addAll(anotherHeros);
        System.out.println("把另一个ArrayList的元素都加入到当前ArrayList:");
        System.out.println("ArrayList heros:\t" + heros);
        
        
        
        
        
    }

}

相关文章

网友评论

      本文标题:AddAllCollection

      本文链接:https://www.haomeiwen.com/subject/ppxnuctx.html