String字串 切割和替換
阿新 • • 發佈:2018-12-12
public static void main(String[] args) { String str = "adb,de,fg"; /** * 在當前字串中,用後面的替換掉字串中所有出現的前面的,返回新的字串 */ String replace = str.replace(",", "@"); System.out.println(replace); System.out.println("******************************"); /** * 如果原字串中有逗號,則用逗號分割成陣列,如果沒有逗號,則將整個字串弄成一個數組,即這個陣列只有一個元素就是這個字串 */ String str1 = "good,fuck"; String[] split = str1.split(","); System.out.println(Arrays.toString(split)); }