Write a Java Program to Remove or Delete Words from String using Inbuilt Function. For delete any particular word from the string in Java Programming, first, you have to ask to the user to enter the string,then second ask to enter the any word present in the string to delete that word from the string.
After asking the two, now check for the presence of that word and perform the deletion of that word from the sentence as shown in the following program.
Example –
This method is shortcut method that uses the method replaceAll( ) to replace all the words with no-space from the string then copy that string into another string without having any that particular words.
Java String replaceAll() :
The java string replaceAll() method returns a string replacing all the sequence of characters matching regex and replacement string.
Syntax :
Parameters
Return Value
Following Java program removes all the words present in the string using inbuilt function.We use the function named replaceAll() to remove or delete all the words from the string.
Here is source code of the Java Program to remove given word from a string. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
SOURCE CODE ::
OUTPUT : :
need an explanation for this answer? contact us directly to get an explanation for this answer