我們可以使用trim()方法從字符串中刪除所有前導(dǎo)和尾隨空格和控制字符。
trim()方法刪除字符串中所有前導(dǎo)和尾隨字符,其Unicode值小于\ u0020(十進(jìn)制32)。例如,
replace()方法將舊字符和新字符作為參數(shù)。
它通過(guò)將新字符替換所有出現(xiàn)的舊字符返回一個(gè)新的String對(duì)象。例如,
public class Main { public static void main(String[] args) { String oldStr = new String("tooth"); String newStr = oldStr.replace("o", "e"); System.out.println(newStr); } }
上面的代碼生成以下結(jié)果。
更多建議: