好像可以用这种方式。
打印结果如下:
[aaa, aab, abc, baa, bba, bca, azz]
[hhh, hhh, hhh]
[aaa, aab, hhh, hhh, hhh, bca, azz]
- import java.util.*;
- class FillDemo
- {
- public static void main(String[] args)
- {
- List<String> list = new ArrayList<String>();
- list.add("aaa");
- list.add("aab");
- list.add("abc");
- list.add("baa");
- list.add("bba");
- list.add("bca");
- list.add("azz");
- System.out.println(list);
- fill(list,2,5,"hhh");
- }
- public static void fill(List<String> list,int start,int end,String str)
- {
- List<String> l2 = list.subList(start,end);
- Collections.fill(l2,str);
- System.out.println(l2);
- System.out.println(list);
- }
- }
复制代码 |