Java split () method with two separators

See the English answer > java – splitting string based on multiple delimiters

abababa:nsndnfnng.leleelld_kdjdh

I want to split it into ":" and ".", So that I can get the following list:

{abababa,nsndnfnng,eleelld_kdjdh}

How do I call split () once?

Solution

You are looking for a string#split method Because it accepts regular expressions that will describe delimiters, your code may look like

String[] result = yourString.split("[:.]");
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>