Thomas Thomas - 1 month ago 9
Java Question

string.replaceAll(...) is returning memory address instead of string

I am using the following code to take out the periods (".") in a string:

String stripPunctuation = tempSentence.replaceAll(".", "");

But the console is printing a memory location of the String instead of the string itself. The first line prints out tempSentence successfully, but the third line stripPunctuation prints out a memory address.


replaceAll takes in a regular expression. '.' meaning any character except newline. try escaping your '.' with a blackslash (ie: '\\.')

or as gulllie said in the comments, you can also use String.replace(String,String)