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

ParameterDescriptionRequired/Optional
operatorIt 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

Test it Now

Output:

Vector elements: [10, 2, 30, 40, 2]
New vector elements: [10, 20, 30, 40, 20]

Example 2

Test it Now

Output:

Vector elements: [Java, Python, Android, Java, Ruby]
New vector elements: [JavaTpoint, Python, Android, JavaTpoint, Ruby]

Next TopicJava Vector




Latest Courses