-5

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.

Pete Becker
  • 74,985
  • 8
  • 76
  • 165
Pankaj
  • 1
  • 1

1 Answers1

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