Java Collections replaceAll() MethodThe replaceAll() method of Java Collections class is used to replace all occurrences of one specified value in a list with the other specified value. SyntaxFollowing is the declaration of replaceAll() method: Parameter
ReturnsThe replaceAll() method returns true if the list contained one or more elements e such that (oldVal==null ? e==null : oldVal.equals(e)). ExceptionsUnsupportedOperationException- It throws this exception if the specified list or its list-iterator does not support the set operation. Compatibility VersionJava 1.4 and above Example 1Test it NowOutput: Initial values are :[Java, SSSIT, HINDI100, Java] Value after replace :[JavaTpont, SSSIT, HINDI100, JavaTpont] Example 2Test it NowOutput: Original List:- [one, two, one] Boolean: true Value after replace:- [three, two, three] Example 3Test it NowOutput: Original List: [10, 20, 10, 40, 50, 10] Boolean: true Value after Replace: [400, 20, 400, 40, 50, 400] Next TopicJava Collections Class |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India