1. 用Java自带的函数str.toString().replace(" ","%20") public class Solution { public String replaceSpace(StringBuffer str) { return str.toString().replace(" ", "%20"); } }2. 开辟一个新的字符串 当遇到 " ",就追加 "%20",否则遇到什么追加(append)什么 import java.util.*; public class Solution { public String replaceS...