List element replacing
In this chapter you will learn:
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;
/*ja v a 2s .c om*/
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:
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » Collections