Replace value in a list

static<T> boolean replaceAll(List<T> list, T oldVal, T newVal)
Replaces all occurrences of one specified value in a list with another.

import java.util.Collections;
import java.util.Vector;

public class Main {
  public static void main(String[] args) {
    Vector<String> v = new Vector<String>();

    v.add("A");
    v.add("B");
    v.add("A");
    v.add("C");
    v.add("D");

    System.out.println(v);
    Collections.replaceAll(v, "A", "java2s.com");
    System.out.println(v);
  }
}
  

The output:


[A, B, A, C, D]
[java2s.com, B, java2s.com, C, D]
Home 
  Java Book 
    Collection  

Collections:
  1. Collections
  2. Get empty collection from Collections
  3. Do binary search
  4. Copy value to a List
  5. Get Enumeration from collection, create list from Enumeration
  6. Fill a list
  7. Get the max and min value from a Collection
  8. Fill n Copy object to a list
  9. Replace value in a list
  10. Reverse a list
  11. Get comparator in reverse order
  12. Rotate and shuffle a list
  13. Create singleton
  14. Sort a list
  15. Swap element in a list
  16. Get a synchronized collection
  17. Return an unmodifiable view of collections