Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.9k points)

Integer i = ...

switch (i){

    case null:

        doSomething0();

        break;    

    }

In the code above I cant use null in switch case statement. How can I do this differently? I can't use default because then I want to do something else.

1 Answer

0 votes
by (46k points)

Try: 

switch ((i != null) ? i : DEFAULT_VALUE) {

        //...

}

Related questions

0 votes
1 answer
asked Dec 22, 2020 in SQL by Appu (6.1k points)
+1 vote
2 answers
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...