I am trying to replace a +
character into a hyphen
I have in my string.
String str = \"word+word\";
str.replaceAll(\'+ \', \'-\');
Just use replace
:
str = str.replace('+', '-');
This one doesn't work on regex but take characters as they are.
Also as you see you have to reassing value again to your str
variable because String
in Java are immutable. In this case method replace
doesn't change current String
(str
) but create new one with replaced +
to '-'.