Here you can find the source of trimToEmpty(String value)
Parameter | Description |
---|---|
value | The value to trim. |
public static String trimToEmpty(String value)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**/*from w w w . ja v a 2s . c om*/ * Trims the given {@code value}, returns {@code empty} if {@code null}. * * @param value * The value to trim. * @return the given {@code value} trimmed or {@code empty} if {@code null}. */ public static String trimToEmpty(String value) { if (isBlank(value)) { return ""; } return value.trim(); } /** * Returns if the given {@code value} is blank. * <p/> * <pre> * isBlank(null) -> true * isBlank("") -> true * isBlank(" ") -> true * isBlank(" test") -> false * isBlank(" a ") -> false * </pre> * * @param value * The value to test. * @return {@code true} if the given {@code value} is {@code null} or {@code empty}. */ public static boolean isBlank(String value) { return value == null || value.trim().isEmpty(); } /** * Trims the given {@code value}. * * @param value * The value to trim. * @return the given {@code value} trimmed or {@code null}. */ public static String trim(String value) { if (value == null) { return null; } return value.trim(); } /** * Returns if the given {@code collection} is {@code null} or empty. * * @param collection * The collection to test. * @return {@code true} if the given {@code collection} is {@code null} or {@code empty}. */ public static <C extends Collection<?>> boolean isEmpty(C collection) { return collection == null || collection.isEmpty(); } /** * Returns if the given {@code array} is {@code null} or empty. * * @param array * The array to test. * @return {@code true} if the given {@code array} is {@code null} or {@code empty}. */ public static <T extends Object> boolean isEmpty(T[] array) { return array == null || array.length == 0; } /** * Returns if the given {@code map} is {@code null} or empty. * * @param map * The map to test. * @return {@code true} if the given {@code map} is {@code null} or {@code empty}. */ public static <M extends Map<?, ?>> boolean isEmpty(M map) { return map == null || map.isEmpty(); } }