Home » Java Vector replaceAll() Method with Examples

Java Vector replaceAll() Method with Examples

by Online Tutorials Library

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

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: [TutorAspire, Python, Android, TutorAspire , Ruby]  

Next TopicJava Vector

You may also like