Here you can find the source of truncateString(String str, int length)
static public String truncateString(String str, int length)
//package com.java2s; public class Main { static public String truncateString(String str, int length) { if (str == null) return null; String retValue;// www . j a va 2 s.c o m if (str.length() <= length) { retValue = str; } else { retValue = str.substring(0, length); } return retValue; } }