Here you can find the source of truncate(String s, int i)
public static String truncate(String s, int i)
//package com.java2s; public class Main { /** Truncates a String s to length i or less */ public static String truncate(String s, int i) { if (s == null) { return null; }//from ww w . j a v a 2 s . c om if (i < 1) { return null; } if (s.length() > i) { return s.substring(0, i); } else { return s; } } }