Java: Get last element after split

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

    With Guava:

    final Splitter splitter = Splitter.on("-").trimResults();
    assertEquals("Günnewig Uebachs", Iterables.getLast(splitter.split(one)));
    assertEquals("Madison", Iterables.getLast(splitter.split(two)));
    

    Splitter, Iterables

提交回复
热议问题