I have some String
s consisting of only digits, and I want to split it whenever the character changes.
For example:
"11101100112021120"
goes to:{"111", "11", "11", "2", "2", "11", "2"}
"222222222"
goes to{"222222222"}
"222222122"
goes to{"222222", "1", "22"}
"000000000"
goes to{}
"0000100000"
goes to{"1"}
"11121222212112133321"
goes to{"111", "2", "1", "2222", "1", "2", "11", "2", "1", "333", "2", "1"}
I want a nice way to do this.
I know two ways to go about this: just brute forcing, or adding section by section. Or, I could go through and remove all 0's and replace with a 0, then add 0's when characters change, and then just do a split on 0's, but both of those ways just look dumb. If anyone has any idea on a better/prettier way to do this, regex or logic, it'd be nice.