Replace All Elements Of ArrayList in Java

Description

The following code shows how to replace All Elements Of ArrayList.

Example


//from w  w  w  .  j  a  va2 s .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("D");

    System.out.println(arrayList);
    Collections.fill(arrayList, "java2s.com");
    System.out.println(arrayList);

  }

}

The code above generates the following result.





















Home »
  Java Tutorial »
    Java Collection »




Java ArrayList
Java Collection
Java Comparable
Java Comparator
Java HashMap
Java HashSet
Java Iterator
Java LinkedHashMap
Java LinkedHashSet
Java LinkedList
Java List
Java ListIterator
Java Map
Queue
Java Set
Stack
Java TreeMap
TreeSet