Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java split () method with two delimiters [duplicate]

Tags:

java

I have a string like

abababa:nsndnfnng.leleelld_kdjdh

I want to split it on ":" and ".", so that I get a list as follows:

{abababa, nsndnfnng, eleelld_kdjdh}

how can I do this with calling the split() once?

like image 834
Alex Avatar asked Jan 07 '23 08:01

Alex


1 Answers

You are looking for String#split method. Since it accepts regex which will describe delimiter your code could look like

String[] result = yourString.split("[:.]");
like image 109
Pshemo Avatar answered Jan 23 '23 05:01

Pshemo