Programming/Java
remove null reference in Java List
halatha
2011. 10. 7. 03:23
http://stackoverflow.com/questions/1239579/helper-in-order-to-remove-null-reference-in-java-list
import java.util.*; public class ListTest { public static void main(String[] args) { final List<Integer> iList = new ArrayList<Integer>(); for ( int i = 0; i < 10; ++i ) { if ( i % 2 == 0 ) iList.add(i); else iList.add(null); } iList.remove(0); System.out.println(iList + "\tsize " + iList.size()); iList.removeAll(Collections.singletonList(null)); System.out.println(iList + "\tsize " + iList.size()); } }