原以为fill方法是填充collection的。测试:
显示[] , 没添进去。 后来得知fill方法是替换已存在元素的。不能添加~
[hello, world]
[joey, joey]
List<String> list = new ArrayList<String>(6);
Collections.fill(list,"hello world!");
System.out.println(fill);显示[] , 没添进去。 后来得知fill方法是替换已存在元素的。不能添加~
List<Stirng> list = new ArrayList<String>(Arrays.asList("hello","world"));
System.out.println(list);
Collections.fill(list, "joey");
System.out.println(list);[hello, world]
[joey, joey]
本文介绍了Java中使用Collections.fill方法填充集合的过程及注意事项。通过实例演示了如何将指定元素填入已有元素的集合中,并强调该方法不能用于向集合添加新元素。
550

被折叠的 条评论
为什么被折叠?



