java 可变参数
package dmeo.array;
public class VariableParameter {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println(change("asf<p>ege<br>","<br>","<p>"));
}
public static String change(String...strings){
String str = strings[0];
for (int i = 1; i < strings.length; i++) {
str.replaceAll(strings[i], "\n");
//System.out.println(strings[i]);
//System.out.println(str);
}
return str;
}
}
我只是想将字符串里的<br>换成\n,为什么用可变参数这样子传进去不行的呢?
java
------解决方案--------------------要给str赋值,replaceAll并不会对str操作,而是产生新的字符串.
str = str.replaceAll(strings[i], "\n");
------解决方案-------------------- public static void main(String[] args) {
System.out.println(change("asf<p>ege<br>","<br>","<p>"));
}
public static String change(String...strings){
String str = strings[0];
for (int i = 1; i < strings.length; i++) {
str= str.replaceAll(strings[i], "\n");
}
return str;
}
}
------解决方案--------------------
+1,你没接收回来