How do I replace elements in a list with another?
For example I want all two to become one?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use:
From the documentation:
The method also return a
booleanto indicate whether or not any replacement was actually made.java.util.Collectionshas many morestaticutility methods that you can use onList(e.g.sort,binarySearch,shuffle, etc).Snippet
The following shows how
Collections.replaceAllworks; it also shows that you can replace to/fromnullas well: