Here you can find the source of truncate(final String value, final int width)
Parameter | Description |
---|---|
value | String to pad |
width | Total width of output string |
public static String truncate(final String value, final int width)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w w w .java 2s. com*/ * Truncate a string if the desired with is less than the length of the input string. * * @param value String to pad * @param width Total width of output string * @return */ public static String truncate(final String value, final int width) { if (width >= value.length()) { return value; } return value.substring(0, width - 3) + "..."; } }