Here you can find the source of containsNullsOrEmptyStrings(Collection
Parameter | Description |
---|---|
c | a Collection |
public static boolean containsNullsOrEmptyStrings(Collection<String> c)
//package com.java2s; /*/* w w w . j a v a2 s . co m*/ * Copyright 2014 Johns Hopkins University * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Collection; public class Main { /** * Returns true if {@code c} contains empty Strings or {@code null} references. * * @param c a Collection * @return true if {@code c} contains empty Strings or {@code null} references. */ public static boolean containsNullsOrEmptyStrings(Collection<String> c) { for (String s : c) { if (isEmptyOrNull(s)) { return true; } } return false; } /** * Returns true if {@code array} contains empty Strings or {@code null} references. * * @param array an array * @return true if {@code array} contains empty Strings or {@code null} references. */ public static boolean containsNullsOrEmptyStrings(String[] array) { for (String s : array) { if (isEmptyOrNull(s)) { return true; } } return false; } /** * Returns true if <code>s</code> is empty or <code>null</code>. * * @param s a string * @return true if <code>s</code> is empty or <code>null</code>. */ public static boolean isEmptyOrNull(String s) { return isNull(s) || isEmpty(s); } /** * Returns <code>true</code> if <code>o</code> is <code>null</code>. * * @param o a object * @return true if <code>o</code> is null */ public static boolean isNull(Object o) { return o == null; } /** * Returns <code>true</code> if <code>s</code> is the empty string. Returns * <code>false</code> if <code>s</code> is <code>null</code> or not empty. * * @param s a string * @return true if <code>s</code> is empty */ public static boolean isEmpty(String s) { if (s == null) { return false; } return s.trim().length() == 0; } }