If you simply trying to replace one character like that, use the replace method:
class ReplaceAll
{
public static void main(String[] args)
{
String s = "Replace /, /, and /";
String replace = s.replace('/','r');
System.out.println(replace);
}
}
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
A common mistake is for people to expect replaceAll to literally replace all occurrances one string with another, but that's not what it does!
replaceAll() uses a regular expression to determine what to replace. If the string you're giving it as the pattern to replace doesn't compile to what you think it does it will give unexpected results.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337