Here you can find the source of removeNulls(Object[] arr)
arr
less any null elements
public static Object[] removeNulls(Object[] arr)
//package com.java2s; /* This file is part of Math4J. * Math4J is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version./*from w ww . ja va 2 s . c o m*/ * * Math4J 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Math4J; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * * Copyright 2005 Anthony Magee */ import java.util.ArrayList; public class Main { /** * Removes all null elements in an Object array. Be sure to cast the array * back to the class type you need. * * @return array <code>arr</code> less any null elements */ public static Object[] removeNulls(Object[] arr) { ArrayList<Object> reply = new ArrayList<Object>(arr.length); for (int i = 0; i < arr.length; i++) { if (arr[i] != null) reply.add(arr[i]); } return reply.toArray(); } }