我想只替换一个字符串的一个字符。但是,只要字符在字符串中出现多次,所有这些字符都将被替换,而我只希望替换特定字符。例如:替换字符串的单个字符
String str = "hello world";
str = str.replace(str.charAt(2), Character.toUpperCase(str.charAt(2)));
System.out.println(str);
给出结果:
heLLo worLd
,而我希望它是:
heLlo world
我能做些什么来实现这一目标?
请参阅此链接了解如何解决这个问题的方法:http://stackoverflow.com/questions/6952363/replace-a-character-at-a-specific-index-in-a-string – slashNburn