Java Array Empty Check getWithoutEmptyParams(String[] cmdarray)

Here you can find the source of getWithoutEmptyParams(String[] cmdarray)

Description

get Without Empty Params

License

Open Source License

Return

a new array without any null/empty elements originally contained in the array.

Declaration

private static String[] getWithoutEmptyParams(String[] cmdarray) 

Method Source Code

//package com.java2s;
/******************************************************************************
* Copyright (C) 2013  Fabio Zadrozny//from   w ww  .j a  va2 s.  c o  m
*
* 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:
*     Fabio Zadrozny <fabiofz@gmail.com> - initial API and implementation
******************************************************************************/

import java.util.ArrayList;

public class Main {
    /**
     * @return a new array without any null/empty elements originally contained in the array.
     */
    private static String[] getWithoutEmptyParams(String[] cmdarray) {
        if (cmdarray == null) {
            return null;
        }
        ArrayList<String> list = new ArrayList<String>();
        for (String string : cmdarray) {
            if (string != null && string.length() > 0) {
                list.add(string);
            }
        }
        return list.toArray(new String[list.size()]);
    }
}

Related

  1. areArraysEqual(byte[] arr1, byte[] arr2, boolean dontDistinctNilAndEmpty)
  2. getNonemptySubsets(Object[] objects)
  3. hasOneEmpty(String[] args)
  4. isEmpty(boolean[] values)
  5. isEmpty(byte[] array)
  6. isEmpty(E[] array)