Java: Get last element after split

后端 未结 12 1837
慢半拍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:14

    In java 8

    String lastItem = Stream.of(str.split("-")).reduce((first,last)->last).get();
    

提交回复
热议问题