Here you can find the source of truncateString(String str, int size)
public static String truncateString(String str, int size)
//package com.java2s; //License from project: Open Source License public class Main { public static String truncateString(String str, int size) { if (size <= 0 || size > str.length()) { return str; }/*from ww w . jav a2s . c o m*/ return str.substring(0, size); } public static String substring(String str, int offset, int length) { if ((offset + length) > str.length()) { length = str.length() - offset; } return str.substring(offset, offset + length); } }