Java 例 - List 要素の置換
以下の例は、Collections クラスの replaceAll() を使用して List 内の指定されたすべての要素を置換する方法を示しています:
Main.java ファイル
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);
}
}
上記コードの実行結果は以下のとおりです:
List :[one, Two, three, Four, five, six, one, three, Four] replaceAll: [hundrea, Two, three, Four, five, six, hundrea, three, Four]その他の拡張
Java 例