- 以下实例演示了如何使用 Collections 类的 replaceAll() 来替换List中所有的指定元素:
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class ImoocStudent {
public static void main(String[] args) throws Exception{
List list = Arrays.asList("one two three four fix six one three".split(" "));
System.out.println("list:" + list);
Collections.replaceAll(list,"one","fuck");
System.out.println("replaceAll:" + list);
}
}
list:[one, two, three, four, fix, six, one, three]
replaceAll:[fuck, two, three, four, fix, six, fuck, three]
标签:six,list,three,four,replaceAll,Collections
From: https://www.cnblogs.com/pansidong/p/17442585.html