In java, use this:
str = str.replace("\\", "https://stackoverflow.com/");
Note that the regex version of replace, ie replaceAll(), is not required here; replace() still replaces all occurrences of the search term, but it searches for literal Strings, not regex matches.