10.24 java题目训练
String newStr = new String(array, 0, size);//其作用是将array函数从0到size由数组变成字符串。
源代码:
class Solution {
public String replaceSpace(String s) {
int length = s.length();
char[] array = new char[length * 3];
int size = 0;
for (int i = 0; i < length; i++) {
char c = s.charAt(i);
if (c == ’ ') {
array[size++] = ‘%’;
array[size++] = ‘2’;
array[size++] = ‘0’;
} else {
array[size++] = c;
}
}
String newStr = new String(array, 0, size);
return newStr;
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)