Here you can find the source of truncate(String str, int max)
public static String truncate(String str, int max)
//package com.java2s; // Licensed under the Academic Free License version 3.0 public class Main { /**/*w ww .j a va 2s . c om*/ * Ensure that the given string is no more than 'max' characters long. */ public static String truncate(String str, int max) { return (str.length() > max) ? str.substring(0, max) : str; } }