Java Collections.replaceAll(List <T> list, T oldVal, T newVal)

Syntax

Collections.replaceAll(List <T> list, T oldVal, T newVal) has the following syntax.

public static <T> boolean replaceAll(List <T> list,   T oldVal,   T newVal)

Example

In the following code shows how to use Collections.replaceAll(List <T> list, T oldVal, T newVal) method.


/*from  www  .j  a  v a 2  s.com*/
import java.util.Collections;
import java.util.List;
import java.util.Vector;

public class Main {
   public static void main(String[] args) {
      // create vector
      List<String> vector = new Vector<String>();
      
      // populate the vector
      vector.add("R");
      vector.add("B");
      vector.add("R");
      vector.add("java2s.com");
     
      System.out.println("Initial values are :"+vector);
      
      Collections.replaceAll(vector, "R", "java2s.com");
      
      System.out.println("Value after replace :"+ vector);
   }
}

The code above generates the following result.