Java examples for Collection Framework:ArrayList
Replace all occurrences of specified element of ArrayList
import java.util.ArrayList; import java.util.Collections; public class Main { public static void main(String[] args) { ArrayList arrayList = new ArrayList(); //from w w w . j a va 2s.c o m arrayList.add("A"); arrayList.add("B"); arrayList.add("A"); arrayList.add("C"); arrayList.add("D"); System.out.println("ArrayList Contains : " + arrayList); Collections.replaceAll(arrayList, "A","Replace All"); System.out.println("After Replace All, ArrayList Contains : " + arrayList); } }