Here you can find the source of shorten(String nameForUI, int maxLen)
public static String shorten(String nameForUI, int maxLen)
//package com.java2s; /****************************************************************************** * Copyright (C) 2012-2013 Fabio Zadrozny and others * * 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:/* www. jav a 2s. co m*/ * Fabio Zadrozny <fabiofz@gmail.com> - initial API and implementation * Jonah Graham <jonah@kichwacoders.com> - ongoing maintenance ******************************************************************************/ public class Main { public static String shorten(String nameForUI, int maxLen) { if (nameForUI.length() >= maxLen) { maxLen -= 5; int first = maxLen / 2; int last = maxLen / 2 + (maxLen % 2); return nameForUI.substring(0, first) + " ... " + nameForUI.substring(nameForUI.length() - last, nameForUI.length()); } return nameForUI; } }