Here you can find the source of trunc(String s, int length)
public static String trunc(String s, int length)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w. j ava 2 s .c om * Takes a string and a length, and truncates it to that that length. * Returns the original string if the length is greater than the string length; */ public static String trunc(String s, int length) { if (s.length() <= length) return s; else return s.substring(0, length); } }