Question Index

Write a program to remove the null and empty string in list.

Input String List Output String List(Without null and empty{})
[Sachin Tendulkar, Dhoni, "", null, null, Sehwag, Yuvraj Singh, Virat Kohli, Gautam Gambhir, null, "", null] [Sachin Tendulkar, Dhoni, Sehwag, Yuvraj Singh, Virat Kohli, Gautam Gambhir]
[CSE, ECE, "", "", IT, null, EEE, MECH, null, CIVIL] [CSE, ECE, IT, EEE, MECH, CIVIL]
[] EMPTY LIST null
null - NULL LIST null

import java.util.*;
class RemoveNullAndEmptyInList
    public static void main(String s[])
        ArrayList<String> list = new ArrayList<String>();
        list.add("Sachin Tendulkar");
        list.add("Yuvraj Singh");
        list.add("Virat Kohli");
        list.add("Gautam Gambhir");
        list.add("Suresh Raina");
        list.add("Rohit Sharma");
        List<String> result = removeNullAndEmpties(list);
        System.out.println("The output after remove null and empties from list");
        for(String inputString : result)


    public static List<String> removeNullAndEmpties(List<String> list)
        List<String> result = null;
        return result;




Topic: Java ArrayList

Read this topic
Take test on this topic

Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App