Menu
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("Dhoni");
        list.add("");
        list.add("Sehwag");
        list.add("Yuvraj Singh");
        list.add("Virat Kohli");
        list.add("");
        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)
        {
            System.out.println(inputString);
        }

    }


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

}

Doubts

Problems

Topic: Java ArrayList

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App