Thomas Thomas - 1 year ago 71
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.

Answer Source,%20java.lang.String)

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)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download