Android examples for java.lang:array element remove
Remove null value from an array
import java.util.ArrayList; import java.util.List; import java.util.Set; public class Main{ /* ww w. j a va 2 s.co m*/ public static String[] clearNull(String[] array) { ArrayList<String> list = new ArrayList<String>(); for (int i = 0; i < array.length; i++) { if (array[i] != null) { list.add(array[i]); } } return toArray(list); } public static String toString(String[] args) { return toString(args, ","); } public static String toString(String[] args, String separator) { if (Validators.isEmpty(args)) { return null; } StringBuilder buffer = new StringBuilder(); for (int i = 0; i < args.length; i++) { if (i > 0) { buffer.append(separator); } buffer.append(args[i]); } return buffer.toString(); } public static String[] toArray(List<String> list) { return list.toArray(new String[list.size()]); } public static String[] toArray(Set<String> set) { return set.toArray(new String[set.size()]); } }