Given a String and a Word, the task is remove that Word from the String.
Input: String = "Geeks For Geeks", Word = "For" Output: "Geeks Geeks" Input: String = "A computer Science Portal", Word = "Geeks" Output: "A computer Science Portal"
Approach : In Java, this can be done using String replaceAll method by replacing given word with a blank space.
Below is the solution to the above problem:
String: Geeks for Geeks. Word: for Result String: Geeks Geeks. String: for Geeks Geeks. Word: for Result String: Geeks Geeks. String: Geeks Geeks for. Word: for Result String: Geeks Geeks. String: A computer Science Portal. Word: Geeks Result String: A computer Science Portal.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.