Replacing a character by another character in a string in android?
问题 Simply i want to replace a character with another in android.. My code: et = (EditText) findViewById(R.id.editText1); String str = et.getText().toString(); str.replace(' ','_'); et.setText(str); System.out.println(str); But here the "space" is not replaced by "underscore".. I also tried other character too.. please help!! 回答1: Strings are immutable in Java - replace doesn't change the existing string, it returns a new one. You want: str = str.replace(' ','_'); (This is definitely a duplicate,