これが私がしたことです。動作しているようです。私がどこか間違っている場合はコメントしてください:
package com.mypackage;
import java.util.ArrayList;
import java.util.List;
public class TestClass {
public static List<String> splitEqually(final String text, final int size) {
List<String> ret = new ArrayList<String>((text.length() + size - 1) / size);
for (int start = 0; start < text.length(); start += size) {
if (start + size > 0) {
String temp = text.substring(start, Math.min(text.length(), start + size));
int length = temp.length();
for (int i = 0; i < (size - length); i++) {
temp = temp + " ";
}
ret.add(temp);
} else {
ret.add(text.substring(start, Math.min(text.length(), start + size)));
}
}
return ret;
}
public static void main(final String args[]) {
String input = "hello wo";
String str1, str2, str3, str4, str5;
List<String> result = TestClass.splitEqually(input, 3);
try {
str1 = result.get(0);
System.out.println("1: " + result.get(0));
str2 = result.get(1);
System.out.println("2: " + result.get(1));
str3 = result.get(2);
System.out.println("3: " + result.get(2));
str4 = result.get(3);
System.out.println("4: " + result.get(3));
str5 = result.get(4);
System.out.println("5: " + result.get(4));
} catch (IndexOutOfBoundsException e) {
}
}
}