How to split a string in java with change in alphabetical order. For example split aaaabb to aaaa & bb. I tried to sort the string by sort function but i am unable to split alphabets in groups.
Asked
Active
Viewed 86 times
1 Answers
0
Try with,
String str = "aaaaabbb";
String strArray[] = str.split("(?<=(.))(?!\\1)");
for(String value : strArray){
System.out.println(value);
}

Rakesh KR
- 6,357
- 5
- 40
- 55