The first revision of your question lacks enough information to understand what is wrong. Most coding problems start with some input, one or more operations and output. You only show us the operation and some vague language about truncation.
The tooltip on the downvote button says:
This question does not show any research effort; it is unclear or not useful
and the unclear reason fits the bill so one downvote seems appropiate at that time of writing not to mention that I expect your problem with replaceAll
might be already answered somewhere.
The helpcenter as well as this post has guidance on good question writing.
The downvotes on the answer might be explained by the fact that both posts mention that there is no problem with your code. These type of questions can be closed for that reason. At least one poster had the privilege to do so but instead posted an answer. The other poster could have flagged your question.
I'm not a java dev but the answers seem technically OK to me....
Remember that everybody picks-up a downvote now and then. Looking at your questions you seem to do fine, don't spend too much time on those incidents.