I need to convert an array of char into several lines of a certain size. For example, considering this array :
char[] bases = new char[]{'a', 'c', 'c', 't', 'a', 'c', 'a', 't', 'a', 'c', 'c', 't', 'a', 'c', 'a', 't'};
the expected output would be for a size of 5:
accta
catac
ctaca
I'm currently using this code :
int ls = 5;
String str = "";
for (int i = 1; i < bases.length; i++) {
str += bases[i - 1];
if (i%ls == 0) {
str += '\n';
}
}
Is there some built-in function to achieve this in java 8? Is there a better way to solve this ?