Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to Split by ":[" in Java

Tags:

java

split

I have 2 nested HashMaps as a String which I am trying to parse.

My String is as follows :

"20:[cost:431.14, Count:19, Tax:86.228"

Therefore I need to Split by ":[" in order to get my key, 20, For some reason I'm not able to do this.

I have tried :

myString.split(":[") and myString.split("\\:[") but neither seem to work.

Can anyone detect what I have wrong here?

Thanks in Advance

like image 846
malteser Avatar asked Mar 04 '26 19:03

malteser


1 Answers

You have to escape the character [ , but not the character : like below:

String str = "20:[cost:431.14, Count:19, Tax:86.228";
String[] spl = str.split(":\\[");
like image 124
YCF_L Avatar answered Mar 06 '26 09:03

YCF_L