I have a String like below,
String str = "12 67 239 2 47 29";
Here i want to split the above string by using " 2 "
System.out.println(StringUtils.split(str, " 2 ")[0]);
I got a result, 1.
But i want the result like below,
12 67 239 2
How can i do it guys, Please help me.
substringof the string and not tosplitthe string. You can easily do that by implementing a regular expression. It is best that you post the code that you have tried.str.split("(?<=\\s2)\\s+")[0], split accepts a regex as it's first argument..*?\\b2\\b