Replace all occurrences of specified element of ArrayList in Java
Description
The following code shows how to replace all occurrences of specified element of ArrayList.
Example
/*from w w w.j ava 2s . c o m*/
import java.util.ArrayList;
import java.util.Collections;
public class Main {
public static void main(String[] args) {
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("A");
arrayList.add("B");
arrayList.add("A");
arrayList.add("C");
arrayList.add("D");
System.out.println(arrayList);
Collections.replaceAll(arrayList, "A", "java2s.com");
System.out.println(arrayList);
}
}
The code above generates the following result.