// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.ArrayList;
import java.util.List;

public class StringSplit {
    public static List<String> split(String s, int len) {
        List<String> res = new ArrayList<String>();
        int ix = 0;
        while(ix < s.length()) {
            int newix = Math.min(ix + len, s.length());
            res.add(s.substring(ix, newix));
            ix = newix;
        }
        return res;
    }
    public static void main(String[] args) {
        String s = "Der var engang en mand der hed Kurt";
        List<String> lst = split(s, 4);
        for(String p : lst) {
            System.out.println("|" + p + "|");
        }
    }
}
