ReplaceAllInListOfStrings
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ReplaceAllInListOfStrings {
public static void main(String args[]) throws Exception{
List<String> uniqueUserNames = new ArrayList<String>();
uniqueUserNames.add("Sarathy");
uniqueUserNames.add("Gopal");
uniqueUserNames.add("Raja");
uniqueUserNames.add("Sarathy");
System.out.println("Before");
System.out.println(uniqueUserNames);
Collections.replaceAll(uniqueUserNames, "Sarathy", "Parthasarathy");
System.out.println("After");
System.out.println(uniqueUserNames);
}
}
|
Output
Before
[Sarathy, Gopal, Raja, Sarathy]
After
[Parthasarathy, Gopal, Raja, Parthasarathy]
|