Knowledge Walls
John Peter
Pune, Maharashtra, India
List String replaceAll method in Core Java with Example
3078 Views
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]
Best Lessons of "One day One Thing to Know"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details