![]() |
VOOZH | about |
The replaceAll() method of java.util.Collections class is used to replace all occurrences of one specified value in a list with another. More formally, replaces with newVal each element e in the list such that
oldVal == null ? e==null : oldVal.equals(e)
Note: This method has no effect on the size of the list.
Parameters: This method takes the following argument as a Parameter
Return Value: This method returns true if the list contained one or more elements e such that as shown below else false
oldVal== null ? e==null : oldVal.equals(e)
Syntax:
public static boolean replaceAll(List list, T oldVal, T newVal)
Example 1:
Initial Vector :[A, B, A, C] Vector after replace :[TAJMAHAL, B, TAJMAHAL, C]
Example 2:
Initial values are :[20, 30, 20, 30] Value after replace :[400, 30, 400, 30]