
Java 執行個體
以下執行個體示範了如何使用 Collections 類的 replaceAll() 來替換List中所有的指定元素:
import java.util.*;
public class Main {
public static void main(String[] args) {
List list = Arrays.asList("one Two three Four five six one three Four".split(" "));
System.out.println("List :"+list);
Collections.replaceAll(list, "one", "hundrea");
System.out.println("replaceAll: " + list);
}
以上代碼運作輸出結果為:
