Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Java by (4k points)

Is there an easy way to remove substring from a given String in Java?

Example: "Hello World!", removing "o" → "Hell Wrld!"

1 Answer

0 votes
by (46k points)

You can use replace() in java to get the desired result.Syntax of this function is 

public String replace(char oldChar, char newChar)

This function will return a new string in which all occurrences oldChar will be replaced by the newChar.

For your problem, do this

String str = "Hello World!";

str = str.replace("o","");

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...