Java Collection Empty removeEmptyStrings(Collection data)

Here you can find the source of removeEmptyStrings(Collection data)

Description

Remove empty strings from a collection.

License

Open Source License

Parameter

Parameter Description
data The data.

Return

The data with empty entries removed.

Declaration

public static String[] removeEmptyStrings(Collection<String> data) 

Method Source Code


//package com.java2s;
// The MIT License(MIT)

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class Main {
    /**//from  w w  w. j  a va 2  s .c  o  m
     * <p>
     * Remove empty strings from a collection.
     * </p>
     *
     * @param data The data.
     * @return The data with empty entries removed.
     */
    public static String[] removeEmptyStrings(Collection<String> data) {
        List<String> result = new ArrayList<>();

        for (String element : data) {
            if (element == null || element.isEmpty()) {
                continue;
            }

            result.add(element);
        }

        return result.toArray(new String[result.size()]);
    }
}

Related

  1. nullOrEmpty(final Collection in)
  2. nullOrEmptyToDefault(final Collection collection, final Collection defaultValue)
  3. nullToEmpty(Collection c)
  4. nullToEmpty(Collection coll)
  5. orEmpty(T collection)
  6. safeIsEmpty(Collection collection)