import java.util.*;
class CollectionsTest1
{
public static void sop(Object obj)
{
System.out.println(obj);
}
public static void main(String[] args)
{
ArrayList<String> list = new ArrayList<String>();
list.add("af");
list.add("a");
list.add("yta");
list.add("bmvb");
list.add("aee");
sop(list);
Collections.replaceAll(list,"a","b");
sop(list);
//Collections.fill(list,"qq");//将list集合中的元素全部替换为制定元素
//sop(list);
Collections.fill(list.subList(0,3),"QQ");//把list集合中一部分元素替换成指定的元素,
sop(list);
}
} |
|