Create a method to Replace Characters in a String

0

Can someone help me create a method that overrides the characters of a String? For example,

String nova = antiga.replace('a','1'); 

This only replaces a letter.

I wanted to create a method for all the other letters of the alphabet that I could use whenever I wanted to replace the characters of a given String.

    
asked by anonymous 22.08.2017 / 19:47

1 answer

3

The method itself replace has this purpose. Note that there is an overhead that receives two% of% 's as a parameter.

That is, you can do it like this

String nova = antiga.replace("alguma coisa", "outra coisa"); 

See working on repl.it.

    
22.08.2017 / 19:57