Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


What is the equivalent of switch expression in Kotlin? How does it differ from switch?



What is the equivalent of switch expression in Kotlin? How does it differ from switch?..

Answer / Sachin Kant Siddharth

The equivalent of a switch statement in Kotlin is the when expression. The main difference between them is that the when expression provides more flexibility and can handle multiple cases more concisely.nnFor example:nnval day = 5nnwhen (day) {n 1 -> println("Monday")n 2 -> println("Tuesday")n in 3..6 -> println("It's a weekday")n else -> println("It's the weekend")n}nnIn this example, the when expression can handle out-of-range cases more elegantly and supports the 'in' operator to check if a value falls within a range.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Kotlin Interview Questions

How to create static methods in Kotlin?

1 Answers  


What is the difference between declaration variable using val or var in kotlin?

1 Answers  


Which companies use kotlin?

1 Answers  


Why is Kotlin preferred over Java? Important benefits of kotlin?

1 Answers  


Why is Kotlin interoperable with Java?

1 Answers  


Is there any Ternary Conditional Operator in Kotlin like in Java?

1 Answers  


How is kotlin integrated with Gradle?

1 Answers  


How to write multiline string in kotlin?

1 Answers  


What are some of the features which are there in Kotlin but not In Java?

1 Answers  


What is the difference between Val and var declaration?

1 Answers  


How do you declare ranges operator in kotlin?

1 Answers  


Why you should switch to Kotlin from Java?

1 Answers  


Categories