int currentKeySize=8;
String message = new String();
message="This is a test message";
String[] splitMessage = new String[currentKeySize];
Arrays.fill(splitMessage,"");
for (int i = 0; i < message.length(); ++i) {
splitMessage[i % splitMessage.length] += message.charAt(i);
}
for (int i = 0; i < splitMessage.length; ++i) {
System.out.println(splitMessage[i]);
}
This code takes a message and splits it into an array of size 8, one character at the time so char(0) goes to String(0)...char(7) to String(7) and char(8) back to String(0).
I have whole program working around this concept and it is great...however now I have to dynamically modify currentKeySize,preferably using 'for' loop so it goes from 1 or 2 (number of splits) to n (lets say 20 splits).
I am aware of ArrayList< String >, however I did not have much luck with it as it is pretty new concept to me.I cannot figure out how to make it work in similar fashion to what I have here with appending characters.
Could someone demonstrate correct use of ArrayList< String >(did not accept without spaces between <>) to perform the same way as what is posted above?
Any help will be appreciated!
SOLVED. Thanks to micneer for exactly what I asked for =).