How to split the string \"Thequickbrownfoxjumps\" to substrings of equal size in Java.
Eg. \"Thequickbrownfoxjumps\" of 4 equal size should give th
Here's a one-liner version which uses Java 8 IntStream to determine the indexes of the slice beginnings:
String x = "Thequickbrownfoxjumps";
String[] result = IntStream
.iterate(0, i -> i + 4)
.limit((int) Math.ceil(x.length() / 4.0))
.mapToObj(i ->
x.substring(i, Math.min(i + 4, x.length())
)
.toArray(String[]::new);