How to split the string \"Thequickbrownfoxjumps\" to substrings of equal size in Java. Eg. \"Thequickbrownfoxjumps\" of 4 equal size should give th
\"Thequickbrownfoxjumps\"
A StringBuilder version:
StringBuilder
public static List getChunks(String s, int chunkSize) { List chunks = new ArrayList<>(); StringBuilder sb = new StringBuilder(s); while(!(sb.length() ==0)) { chunks.add(sb.substring(0, chunkSize)); sb.delete(0, chunkSize); } return chunks;
}