Here you can find the source of emptyStringIfNull(String string)
Parameter | Description |
---|---|
string | the string to check. |
public static final String emptyStringIfNull(String string)
//package com.java2s; /**//from ww w. j a v a2 s .co m * $RCSFile$ * $Revision: 18467 $ * $Date: 2005-02-15 14:36:52 -0800 (Tue, 15 Feb 2005) $ * * Copyright (C) 2004-2008 Jive Software. All rights reserved. * * This software is published under the terms of the GNU Public License (GPL), * a copy of which is included in this distribution, or a commercial license * agreement with Jive. */ public class Main { /** * Returns an empty string if null. * @param string the string to check. */ public static final String emptyStringIfNull(String string) { if (!hasLength(string)) { return ""; } return string; } /** * Returns <CODE>true</CODE> if the specified {@link String} is not * <CODE>null</CODE> and has a length greater than zero. This is * a very frequently occurring check. */ public static final boolean hasLength(String s) { return (s != null && s.length() > 0); } }