Replacing a character by another character in a string in android? Replacing a character by another character in a string in android? android android

Replacing a character by another character in a string in android?


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, but I don't have enough time right now to find an appropriate one...)


String is immutable and you cannot change it. So, you need to do this:

str = str.replace(' ','_');


See code:

et = (EditText) findViewById(R.id.editText1);String str = et.getText().toString();str = str.replace(' ', '_');System.out.println(str);