Here you can find the source of truncate(String string, int n, String suffix)
public static String truncate(String string, int n, String suffix)
//package com.java2s; //License from project: Open Source License public class Main { public static String truncate(String string, int n, String suffix) { if (string.length() - suffix.length() > n) { return string.substring(0, n) + suffix; }//from w w w . jav a 2 s. c o m return string; } }