Java 例 - List 要素の置換

Java 实例Java 例

以下の例は、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 实例Java 例

その他の拡張