Here you can find the source of truncate(String s, int length)
Parameter | Description |
---|---|
s | The string to truncate |
length | The maximum length |
public static String truncate(String s, int length)
//package com.java2s; //License from project: Open Source License public class Main { /**//ww w .ja va 2s. c o m * Truncate the input string to be at most the input length * @param s The string to truncate * @param length The maximum length * @return A truncated string with length 15, or the input string */ public static String truncate(String s, int length) { if (s.length() <= length) return s; return s.substring(0, length); } public static String truncate(String s) { return truncate(s, 15); } }