java.util.Collections.replaceAll() 方法


java.util.Collections.replaceAll() 方法

package com.codingdict;

import java.util.*;

public class CollectionsDemo {
   public static void main(String[] args) {

      // create vector
      Vector<String> vector = new Vector<String>();

      // populate the vector
      vector.add("R");
      vector.add("B");
      vector.add("R");

      System.out.println("Initial values are :"+vector);

      // replace 'R' with 'Replace All'
      Collections.replaceAll(vector, "R", "Replace All");

      System.out.println("Value after replace :"+ vector);
   }
}