而編程我接受一個字符串......改變了它使用Arrays.toString()用[]和 - 打印字符串,任何替代?
string.toCharArray()
到字符數組......只好改回字符串(因爲我使用recurion並必須通過字符串作爲每個參數時間)..如何做到這一點..?
我試過使用array.toString()
...但它通過gibberis ..開始與@ ....然後我在這裏搜索,發現約Arrays.toString()
.....但瞭解到,它確實將其轉換爲字符串,但增加[]和......我需要原始的字符串....如何去這個...代碼的繼承人一部分..
public String replace(String str, char ch) {
if(count ==0){
Scanner sc2= new Scanner(System.in);
System.out.println("enter the character to be replaced with ");
c2 =sc2.next().charAt(0);
len=str.length();
}
arr=str.toCharArray();
if(arr[count]==ch){
arr[count]=c2;
}
count++;
str=Arrays.toString(arr); // Problem
if(count<len)
temp=replace(str,ch);
else
temp=str;
return temp;
}
http://docs.oracle.com/javase/7/docs/api/java/lang/ String.html#String(char [])...忽略不需要使用'char []'。 –