Here you can find the source of ellipsize(String text, int maxLength)
public static String ellipsize(String text, int maxLength)
//package com.java2s; /*/*from w w w . ja v a2 s . c o m*/ * Copyright (C) 2014 Markus Junginger, greenrobot (http://greenrobot.de) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * Cuts the string at the end if it's longer than maxLength and appends "..." to it. The length of the resulting * string including "..." is always less or equal to the given maxLength. It's valid to pass a null text; in this * case null is returned. */ public static String ellipsize(String text, int maxLength) { if (text != null && text.length() > maxLength) { return text.substring(0, maxLength - 3) + "..."; } return text; } }