I have a String str = "12345678"; Can anyone tell me why : str.replace('4', 'B'); will give me "123B5678" but : str.replace((char)4, 'B'); won't change str.
replace() requires a char parameter and I can't see anything wrong with casting an int to char. Thanks for any help! Paul
because (char)4 is not '4'. Try this code - System.out.println((char)4); //doesn't print 4 replace() method can't find character with unicode value 4 in the sting. HTH, - Manish