Here you can find the source of trunc(String s1, int length)
public static String trunc(String s1, int length)
//package com.java2s; //License from project: Open Source License public class Main { public static String trunc(String s1, int length) { if (s1 == null) { return ""; }// ww w. j av a2 s. c o m if (s1.length() > length && length <= 2) { return s1.substring(0, length); } if (s1.length() > length) { return s1.substring(0, length - 2) + ".."; } return s1; } }