Here you can find the source of truncate(String string, int length)
"..."
if string was shortened
Parameter | Description |
---|---|
string | string to truncate |
length | length to truncate at |
public static String truncate(String string, int length)
//package com.java2s; public class Main { /**// ww w .j a v a2 s. c o m * Truncates string at given length, appends <code>"..."</code> if string was shortened * @param string string to truncate * @param length length to truncate at * @return if string length is less than or equal to given length then the given string, otherwise the given string truncated at given length with {@code ...} appended */ public static String truncate(String string, int length) { return string.length() > length ? string.substring(0, length) + "..." : string; } }