// 思路:用String的实例方法replace实现替换 class Solution { public String replaceSpaces(StringBuffer str) { String s = str.toString(); String newS = s.replace(" ", "%20"); return newS; } }