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 does interoperable feature work in Kotlin for java ?

1 Answers  


Does Kotlin support primitive datatypes as like in Java?

0 Answers  


How to declare variables in Kotlin?

1 Answers  


Does Kotlin provide any additional functionalities for standard Java packages or standard Java classes?

0 Answers  


List the Basic data types of Kotlin?

1 Answers  


In kotlin, can we create an empty array?

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  


Does you class compile if the package is wrong? Why?

1 Answers  


Give a syntax for declaring a variable as volatile in Kotlin?

1 Answers  


Which companies use kotlin?

1 Answers  


Categories