Here you can find the source of truncateWithDefault(String value, int size, String defaultValue)
Parameter | Description |
---|---|
value | value |
size | size |
defaultValue | defaultValue |
public static String truncateWithDefault(String value, int size, String defaultValue)
//package com.java2s; public class Main { /**/* ww w . j a v a 2 s .c o m*/ * truncateWithDefault. * @param value value * @param size size * @param defaultValue defaultValue * @return String */ public static String truncateWithDefault(String value, int size, String defaultValue) { if (isEmpty(value)) { return defaultValue; } if (value.length() > size) { return defaultValue; } return value; } /** * whether or not the string is null or consists only of whitespace. * @param s * @return boolean * */ public static boolean isEmpty(String s) { return s == null || s.trim().length() == 0; } }