java String split方法會忽略字符串最後的分隔符

版權聲明:本文爲博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/jeffrey_li/article/details/79757717

測試代碼:

public static void main(String[] args) {
    String str = "#1##2##";
    String[] split = str.split("#");
    System.err.println("length:"+split.length);
    for (String string : split) {
      System.out.println(string);
    }
  }

輸出結果:

length:4
(空串)
1
(空串)
2

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章