Online Java Compiler By
JavaTpoint.com
import java.util.*; public class VectorReplaceAllExample2 { public static void main(String arg[]) { //Create an empty vector Vector
vec = new Vector
(); //Add elements in the Vector vec.add("Java"); vec.add("Python"); vec.add("Android"); vec.add("Java"); vec.add("Ruby"); //Display vector elements System.out.println("Vector elements: " +vec); //replace all vector element "Java" with "JavaTpoint" Collections.replaceAll(vec, "Java", "JavaTpoint"); //Display vector elements after replacement System.out.println("New vector elements: " + vec); } }
Output