Question: (Java: Replace word in String) How to make a Java method recursive when it has to replace a word in a string? I need a

(Java: Replace word in String) How to make a Java method recursive when it has to replace a word in a string?

I need a method that will take in a sentence and then find and replace all instances of a given word with another given word.

The method I wrote without recursion is:

private static String substitute(String line, String find, String replace) { String[] words = line.split(" "); for (int k = 0; k if (words[k].equals(matchWordCase(words[k], find))){ words[k] = matchWordCase(words[k], replace);} else{} String done = String.join(" ", words);

return done; }

How would I go about writing recursive code that would do the same thing?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!