Java String Empty emptyString(final String string)

Here you can find the source of emptyString(final String string)

Description

Check if a string is null , empty or contains only whitespaces.

License

Open Source License

Parameter

Parameter Description
string String to check

Return

true, if this String is null , empty or contains only whitespaces; false otherwise

Declaration

public static boolean emptyString(final String string) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015, 2017 Lablicate GmbH.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from w  ww.ja  va  2  s  .  com
 * Dr. Alexander Kerner - initial API and implementation
 *******************************************************************************/

public class Main {
    /**
     * Check if a string is {@code null}, empty or contains only whitespaces.
     *
     * @param string
     *            {@code String} to check
     * @return true, if this {@code String} is {@code null}, empty or contains
     *         only whitespaces; false otherwise
     */
    public static boolean emptyString(final String string) {

        if (string == null)
            return true;
        if (string.length() < 1)
            return true;
        if (string.matches("\\s+"))
            return true;
        return false;
    }
}

Related

  1. coerceValueIfNullOrEmpty(String s, String valueIfNullOrEmpty)
  2. emptyString()
  3. emptyString(final String a, final String defaultString)
  4. emptyString(Object s)
  5. emptyString(String s)
  6. emptyString(String s)
  7. emptyString(String str)