What is replaceAll() in groovy?

replaceAll() is a function in groovy that replaces all occurrences of a string with a specified string.

Syntax


void replaceAll(String text, String replace)

Parameters

  • text: the string that needs to be replaced.

  • replace: the string which would replace text.

Return value

This method returns the modified String.

Code

class Main {
static void main(String[] args) {
String text = "Hello Educative Hello";
println(text.replaceAll("Hello","Edpresso"));
}
}

Output


Edpresso Educative Edpresso
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources