传值有问题!
public static void stringReplace (String text) {
text = text.replace ('j' , 'i');
System.out.println(text);
}
此时打印出来的数据就是替换了的!
有空看看:
http://www.csdn.net/Develop/read_article.asp?id=22025
public static void stringReplace (String text) {
text = text.replace ('j' , 'i');
System.out.println(text);
}
此时打印出来的数据就是替换了的!
有空看看:
http://www.csdn.net/Develop/read_article.asp?id=22025
replace方法是说:如果在string中找到欲替换的字符,则会产生一个新的与原字符串内容相同的字符串,返回该字符串被替换后的结果。并不像其他语言一样对原字符串进行替换。所以你打印原字符串自然没有变化参照下例:
public class Test {
public static String stringReplace (String text) {
return text.replace ('j' , 'i');
} public static void main (String args[]) { String textString = new String ("java");
System.out.println(stringReplace (textString));
System.out.println (textString);
}
}