Q:

Case insensitive String split() method

When I perform
String test="23x34 ";
String[] array=test.split("x"); //splitting using simple letter

I got two items in array as 23 and 34
but when I did
String test="23x34 ";
String[] array=test.split("X"); //splitting using capitalletter

I got one item in array 23x34
So is there any way I can use the split method as case insensitive or whether there is any other method that can help? 

A:

split uses, as the documentation suggests, a regexp. a regexp for your example would be :
"[xX]"

Also, the (?i) flag toggles case insensitivty. Therefore, the following is also correct :
"(?i)x"

In this case, x can be any litteral properly escaped.

A:

Use regex pattern [xX] in split
String x = "24X45";
String[] res = x.split("[xX]");
System.out.println(Arrays.toString(res));

A:

You can also use an embedded flag in your regex:
String[] array = test.split("(?i)x"); // splits case insensitive

