Java: Get last element after split

后端 未结 12 1824
慢半拍i
慢半拍i 2020-12-02 11:31

I am using the String split method and I want to have the last element. The size of the Array can change.

Example:

String one = \"Dü         


        
12条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 12:33

    String str = "www.anywebsite.com/folder/subfolder/directory";
    int index = str.lastIndexOf('/');
    String lastString = str.substring(index +1);
    

    Now lastString has the value "directory"

提交回复
热议问题