String split not returning empty results

前端 未结 9 1507
走了就别回头了
走了就别回头了 2020-12-02 00:12

I\'m trying to use

\"value1:value2::value3\".split(\":\");

Problem is that I want it to include the blank results.

It returns:

9条回答
  •  伪装坚强ぢ
    2020-12-02 01:02

    Using Guava's Splitter class:

    Iterable split = Splitter.on(':').split("value1:value2::value3");
    

    Splitter does not omit empty results by default, though you can make one that does. Though it seems from what others are saying that what you're doing should work as well.

提交回复
热议问题