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.
- Length Of Last Word in a String
- Print last character of each word in a string
- Capitalize the first and last character of each word in a string
- Print first letter of each word in a string using regex
- Extracting each word from a String using Regex in Java
- Get the first letter of each word in a string using regex in Java
- Program to remove consonants from a String
- Remove Leading Zeros From String in Java
- How to remove all white spaces from a String in Java?
- Remove all non-alphabetical characters of a String in Java
- Remove extra delimiter from a String in Java
- Trim (Remove leading and trailing spaces) a string in Java
- Java program to count the characters in each word in a given sentence
- Queue remove() method in Java
- CopyOnWriteArraySet remove() method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Rajput-Ji