Here you can find the source of truncate(final String target, final int maxSize)
static final public String truncate(final String target, final int maxSize)
//package com.java2s; //License from project: Open Source License public class Main { static final public String truncate(final String target, final int maxSize) { return (target.length() > maxSize ? target.substring(0, maxSize) : target); }//from ww w . j a va 2 s . c om }