【Java】集合常用功能(Collections工具类)

2022-01-28  本文已影响0人  如雨随行2020
        List<Person> listB = new ArrayList<>(Collections.nCopies(5, new Person(3)));
        listB.get(0).age = 321;
        System.out.println("listB: " + listB);
        // listB: [Persion{age=321}, Persion{age=321}, Persion{age=321}, Persion{age=321}, Persion{age=321}]
        Person[] persons = {new Person(43), new Person(54)};
        Collections.addAll(listA, persons);
        //等价于 Collections.addAll(listA, new Person(43), new Person(54));
上一篇下一篇

猜你喜欢

热点阅读