Here you can find the source of truncate(String str)
public static String truncate(String str)
//package com.java2s; /******************************************************************************* * Copyright (c) 2007, 2008 Tran Nam Quang. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w ww . j a va2s . c o m*/ * Tran Nam Quang - initial API and implementation *******************************************************************************/ public class Main { /** * Shortens the given string if its length exceeds a fixed limit. */ public static String truncate(String str) { if (str.length() > 32) return str.substring(0, 32) + "..."; //$NON-NLS-1$ return str; } }