remove whitespace element from array in java

ww‮l.w‬autturi.com
remove whitespace element from array in java
/**
 * @author lautturi.com
 * Java example: 
 */

import java.util.*;

public class Lautturi {

	public static void main(String[] args) {

		String[] strArray = { "hello", "lautturi", "", "python", "	", "lau", " ",null,null };

		String[] tempArr = new String[strArray.length];
		int idx = 0;
		for (int i = 0; i < strArray.length; i++) {
			if (strArray[i] != null && !strArray[i].trim().equals("")) {
				tempArr[idx] = strArray[i].trim();
				idx++;
			}
		}
		
		String[] newArray = new String[idx];
		for (int i = 0; i < idx; i++) {
			if (tempArr[i] != null && !tempArr[i].trim().equals("")) {
				newArray[i] = tempArr[i].trim();
			}
		}
		
		System.out.println(Arrays.toString(newArray));

	}
}

output:

[hello, lautturi, python, lau]
Created Time:2017-09-13 14:53:57  Author:lautturi