Monday, 17 March 2014

How to remove null in the List (JAVA)

Just add as below
listnameObject.removeAll(Collections.singleton(null));

For Ex:
public class MapTest {
  public static void main(String[] args) {
    List<String> scores = new ArrayList<String>();
    scores.add("100");
    scores.add("90");
    scores.add("80");
    scores.add("97");
    scores.add(null);
    scores.removeAll(Collections.singleton(null));
   
    for(String a : scores){
      System.out.println(a.toString());
    }
  }
}

O/P:
100
90
80
97

No comments:

Simplest way to display Server Time in JSP using js

THE BELOW CODE WORKS ONLY IN JSP : <html> <body > <table width="95%" border="1" cellpadding="1...