public String replace(CharSequence target,
CharSequence replacement)
Replaces each substring of this string that
matches the literal target sequence with
the specified literal replacement sequence.
The replacement proceeds from the
beginning of the string to the end,for example, replacing "aa" with "b"
in the string "aaa" will result in "ba" rather than "ab".
这里面重点便是Replaces each substring-----说明可以替换字符串中所有的目标字符串(这是与StringBuffer中的replace很大不同),而且不必在意长度不对称问题。
直接翻看文档: 方法原型:public StringBuffer replace(int start, int end, String str) 方法描述: Replaces the characters in a substring of this sequence with characters in the specified String. The substring begins at the specified start and extends to the character at index end - 1 or to the end of the sequence if no such character exists. First the characters in the substring are removed and then the specified String is inserted at start. (This sequence will be lengthened to accommodate the specified String if necessary.)