93
Java Vector replaceAll() Method
The replaceAll() method of Java Vector class is used to replace each element of the list with the result of applying the operator to that element.
Syntax
Following is the declaration of replaceAll() method:
Parameter
Parameter | Description | Required/Optional |
---|---|---|
operator | It is an operator which will apply to each element. | Required |
Return
The replaceAll() method does not return anything.
Exceptions
NullPointerException– This method has thrown an exception if the specified operator is null or if the operator result is a null value and this list does not permit null elements.
Compatibility Version
Java 1.2 and above
Example 1
Output:
Vector elements: [10, 2, 30, 40, 2] New vector elements: [10, 20, 30, 40, 20]
Example 2
Output:
Vector elements: [Java, Python, Android, Java, Ruby] New vector elements: [TutorAspire, Python, Android, TutorAspire , Ruby]
Next TopicJava Vector