public static String ellipsize ( String text , int maxLength , String end ) { if ( text != null && text . length ( ) > maxLength ) { return text . substring ( 0 , maxLength - end . length ( ) ) + end ; } return text ; }
Cuts the string at the end if it s longer than maxLength and appends the given end string to it . The length of the resulting string is always less or equal to the given maxLength . It s valid to pass a null text ; in this case null is returned .