I'm new to using regular expressions, but I think that in an instance like this using them would be the quickest and most ellegant way. I have a binary string, and I need to split it into groups that only contain consecutive zeros or ones, for example:
110001
would be split into
11
000
1
I just can't figure it out, this is my current code, thanks:
class Solution {
public static void main(String args[]) {
String binary = Integer.toBinaryString(67);
String[] exploded = binary.split("0+| 1+");
for(String string : exploded) {
System.out.println(string);
}
}
}
}