Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Java by (1.1k 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 (13.2k 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
asked Nov 13, 2019 in Java by Nigam (4k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.2k users

Browse Categories

...