Skip to content

Instantly share code, notes, and snippets.

@rafaelzomer
Created May 27, 2014 11:30
Show Gist options
  • Select an option

  • Save rafaelzomer/701230d3bbb6a5c6cca2 to your computer and use it in GitHub Desktop.

Select an option

Save rafaelzomer/701230d3bbb6a5c6cca2 to your computer and use it in GitHub Desktop.
Split string in pre-determinate parts, in this case, five.
String text = "aaaaabbbbbccccceeeeefff";
System.out.println(text);
Integer parts = 5;
String[] tokens = text.split("(?<=\\G.{" + parts + "})");
System.out.println(tokens.length)
for(String t : tokens) {
System.out.println(t);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment