I tried to search online to solve this question but I didn\'t found anything.
I wrote the following abstract code to explain what I\'m asking:
String
Here's a succinct implementation using Java8 streams:
String text = "how are you?";
final AtomicInteger counter = new AtomicInteger(0);
Collection strings = text.chars()
.mapToObj(i -> String.valueOf((char)i) )
.collect(Collectors.groupingBy(it -> counter.getAndIncrement() / 4
,Collectors.joining()))
.values();
Output:
[how , are , you?]