Java List Contain containsOnlyEmptyValues(List list)

Here you can find the source of containsOnlyEmptyValues(List list)

Description

Checks if all of the entries in a list of Strings is empty or null.

License

Open Source License

Parameter

Parameter Description
list the list containing strings

Return

true if the list only has null or empty values

Declaration

public static boolean containsOnlyEmptyValues(List<String> list) 

Method Source Code

//package com.java2s;
/* Copyright 2010 - 2014 by Brian Uri!
       /*from   w w  w.jav  a  2  s .c o  m*/
   This file is part of DDMSence.
       
   This library is free software; you can redistribute it and/or modify
   it under the terms of version 3.0 of the GNU Lesser General Public 
   License as published by the Free Software Foundation.
       
   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
   GNU Lesser General Public License for more details.
       
   You should have received a copy of the GNU Lesser General Public 
   License along with DDMSence. If not, see <http://www.gnu.org/licenses/>.
    
   You can contact the author at ddmsence@urizone.net. The DDMSence
   home page is located at http://ddmsence.urizone.net/
 */

import java.util.List;

public class Main {
    /**
     * Checks if all of the entries in a list of Strings is empty or null.
     * 
     * @param list the list containing strings
     * @return true if the list only has null or empty values
     */
    public static boolean containsOnlyEmptyValues(List<String> list) {
        if (list != null) {
            int emptyCount = 0;
            for (String value : list) {
                if (isEmpty(value))
                    emptyCount++;
            }
            return (list.size() == emptyCount);
        }
        return (false);
    }

    /**
     * Checks if a String value is empty. An empty string is defined as one that is null, contains only whitespace, or
     * has length 0.
     * 
     * @param value the value to check.
     * @return a boolean, true if the value is null or zero-length, false otherwise
     */
    public static boolean isEmpty(String value) {
        return (value == null || value.trim().length() == 0);
    }
}

Related

  1. containsNonPositives(List vals)
  2. containsNull(List list)
  3. containsNullElement(List source)
  4. containsOneEqualElem(List first, List second)
  5. containsOnly(List elements, Class clazz)
  6. containsOnlyNulls(List list)
  7. containsOnlySequentialNumbers(List values)
  8. containsOrIsEmpty(List list, Object item)
  9. containsReference(List references, Object toBeFound)