You could use a simple for-loop and the String.substring() method. The index of the loop would start at zero and go up by five; at each step you'd call substring() to make a five-character String (or less if there aren't five characters less.) You can compute the length of the String array before running the loop by dividing the String's length by 5 and rounding up.
Yeah i've tried this. but the problem is at the last iteration of the for loop, when i try to make the 5 charecter string i'm getting an arrayoutofboundexception as the length of the string here is only 3 and not 5.
author and iconoclast
OK, cool. So all you need to do is compute the length of the next string you can make. Let's say "i" is the index of the character at the beginning of the String. You'd like to use "i+5" as the end index, but that might be too far. When is it too far? When it's larger then the length of the String. So what you actually want for the end index is the smaller of "i+5" and "theString.length".
So the two arguments to substring() should be "i" and "the smaller of i+5 and theString.length".
Hmmm. Maybe there's a function that returns the smaller of two ints, somewhere. Maybe in the java.lang.Math class....