Java tutorial
//package com.java2s; public class Main { /** * Strips null Strings from an array of Strings. * * @param str * Array to remove null strings from. * @return String array with null strings removed. */ public static String[] stripNullStrings(String[] str) { if (str == null) return null; // propagate null strings to the end for (int i = str.length - 1; i > 0; i--) { if (str[i] != null && str[i - 1] == null) { str[i - 1] = str[i]; str[i] = null; } } int numvalid = 0; for (int i = 0; i < str.length; i++) if (str[i] != null) numvalid = i + 1; if (numvalid == 0) return null; String tmp[] = new String[numvalid]; System.arraycopy(str, 0, tmp, 0, numvalid); return tmp; } }