Replace All Elements Of ArrayList - Java Collection Framework

Java examples for Collection Framework:ArrayList

Description

Replace All Elements Of ArrayList

Demo Code


import java.util.ArrayList;
import java.util.Collections;
 
public class Main {
 
  public static void main(String[] args) {
    ArrayList arrayList = new ArrayList();
   //w w w  . j a va 2  s  .co m
    arrayList.add("A");
    arrayList.add("B");
    arrayList.add("D");
 
    System.out.println("Before replacement, ArrayList contains : " + arrayList);
   
    Collections.fill(arrayList,"REPLACED");
   
    System.out.println("After replacement, ArrayList contains : " + arrayList);
 
  }
}
 

Result


Related Tutorials