方法一:

public class Solution {
public String replaceSpace(StringBuffer str) {
String a=str.toString();
char[] b = a.toCharArray();
StringBuilder sBuilder = new StringBuilder();
for (char c : b) {
if(c==' ') {
sBuilder.append("%20");
}else {
sBuilder.append(c);
}
}
String e = sBuilder.toString();
return e; }
}
05-06 21:43