Here you can find the source of chop(String string, int length)
public static String[] chop(String string, int length)
//package com.java2s; /*/*from www . jav a 2 s .c o m*/ * Copyright Gergely Nagy <greg@webhejj.hu> * * Licensed under the Apache License, Version 2.0; * you may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 */ public class Main { /** * chop up strings to chunks of the specified length (last chunk may be shorter) */ public static String[] chop(String string, int length) { if (string.length() == 0) { return new String[0]; } int chunkCount = string.length() / length + 1; String[] chunks = new String[chunkCount]; for (int i = 0; i < chunkCount; i++) { chunks[i] = string.substring(i * length, Math.min(string.length(), (i + 1) * length)); } return chunks; } }