Here you can find the source of removeEmptyEntries(String[] array)
public static String[] removeEmptyEntries(String[] array)
//package com.java2s; /*//from ww w.ja va2s .c o m * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class Main { public static String[] removeEmptyEntries(String[] array) { if (array == null || array.length == 0) { return array; } List<String> result = new ArrayList<String>(); for (String entry : array) { entry = removeEmptyEntry(entry); if (entry != null) { result.add(entry); } } if (result.size() == 0) { return null; } return result.toArray(new String[result.size()]); } public static String[] removeEmptyEntries(String[] array, String[] defaultArray) { String[] result = removeEmptyEntries(array); if (result == null) { return defaultArray; } else { return result; } } public static Map<String, String> removeEmptyEntries(Map<String, String> map) { if (map == null) { return null; } Map<String, String> result = new HashMap<String, String>(); for (Map.Entry<String, String> entry : map.entrySet()) { String key = removeEmptyEntry(entry.getKey()); String value = removeEmptyEntry(entry.getValue()); if (key != null && value != null) { result.put(key, value); } } if (result.size() == 0) { return null; } return result; } public static String removeEmptyEntry(String entry) { if (entry == null) { return null; } entry = entry.trim(); if (entry.length() == 0) { return null; } return entry; } }