{"id":5357,"date":"2020-11-27T16:54:20","date_gmt":"2020-11-27T11:24:20","guid":{"rendered":"https:\/\/www.concettolabs.com\/blog\/?p=5357"},"modified":"2023-01-18T06:08:44","modified_gmt":"2023-01-18T06:08:44","slug":"how-to-replace-switch-with-when-in-kotlin","status":"publish","type":"post","link":"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/","title":{"rendered":"How to Replace Switch with When in Kotlin?"},"content":{"rendered":"<p>As a beginner, you might look for how the Kotlin switch statement works. If your background is working in C, Java, etc. then switching to Kotlin works best. There is no switch statement available in Kotlin; instead, it replaces the switch with the when expression.<\/p>\n<p>The switch is used as a two-state user interface element and work as a toggle between ON and OFF like button. One can add a switch into our application layout by using its switch object. By default, the switch is off. Moving on with <a href=\"https:\/\/kotlinlang.org\/\" target=\"_blank\" rel=\"nofollow\"><span style=\"text-decoration: underline;\"><strong>Kotlin<\/strong><\/span><\/a>, then When is replace the Switch operator. A specific block of code needs to execute when the condition fulfilled. One can take help from <a href=\"https:\/\/www.concettolabs.com\/kotlin-app-development\" target=\"_blank\" rel=\"nofollow\"><span style=\"text-decoration: underline;\"><strong>Kotlin App Developers<\/strong><\/span><\/a> and develop android application.<\/p>\n<p><strong>In Kotlin switch case with string, when is mainly used in two ways:<\/strong><\/p>\n<ul>\n<li>When as a statement<\/li>\n<li>When as an expression<\/li>\n<\/ul>\n<p>When&#8217; is an expression compared with other branches. If it used as a statement, the branch values compared sequentially with the argument and execute the corresponding branch where the condition matches. Here in this blog, we\u2019ll look at how switch replaces the when.<\/p>\n<p>Let\u2019s start with understanding <strong>Switch in Kotlin Android<\/strong> and then we\u2019ll check how the when keyword makes our code easier and more understandable.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Switch\"><\/span>Switch<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Suppose you have used a conditional statement where the condition used in the conditional statement applies to a similar type of data. Then instead of that use vast code for the conditional statement. Use the switch to avoid using too many conditional statements in our code. Let\u2019s study with the help of an example.<\/p>\n<p>Let\u2019s consider one example where we have to return emoji based on input spring.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-5382 size-full\" title=\"input spring.\" src=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-2-1-2.png\" alt=\"input spring.\" width=\"839\" height=\"300\" srcset=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-2-1-2.png 839w, https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-2-1-2-300x107.png 300w, https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-2-1-2-768x275.png 768w\" sizes=\"auto, (max-width: 839px) 100vw, 839px\" \/><br \/>\nBut if we rewrite the code using the When statement in Kotlin, then it provides better readability than if\/else. In the above code, if\/else statement replaced with the when statement.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-5363 size-full\" title=\"fun getthe emoji\" src=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/1-1-2.png\" alt=\"fun getthe emoji\" width=\"835\" height=\"250\" srcset=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/1-1-2.png 835w, https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/1-1-2-300x90.png 300w, https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/1-1-2-768x230.png 768w\" sizes=\"auto, (max-width: 835px) 100vw, 835px\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Replace_Switch_Case_Kotlin_with_When\"><\/span>Replace Switch Case Kotlin with When<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-5361 size-full\" title=\"Replace Switch Case Kotlin with When\" src=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-3-2.png\" alt=\"Replace Switch Case Kotlin with When\" width=\"852\" height=\"332\" srcset=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-3-2.png 852w, https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-3-2-300x117.png 300w, https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-3-2-768x299.png 768w\" sizes=\"auto, (max-width: 852px) 100vw, 852px\" \/><\/p>\n<p>Similar to if\/else, the switch is one of the ancient ways to deal with conditional execution. Whereas in Kotlin, we can replace switch case and if\/else with when similarly, we implement the conditional execution. Now the switch can replace with the when statement also to if\/else. Make the code more readable, consistent and adapt quickly with new developers.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Return_values_with_When_Block\"><\/span>Return values with When Block<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Till now, you have seen the ability of when the block in <strong>Kotlin switch case<\/strong> with spring replaces conditional statements. But well, it can do more than this. Let&#8217;s say, it can return the values from the conditional blocks after you execute the necessary steps.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-5362 size-full\" title=\"Return values with When Block\" src=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-4-2.png\" alt=\"Return values with When Block\" width=\"843\" height=\"266\" srcset=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-4-2.png 843w, https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-4-2-300x95.png 300w, https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-4-2-768x242.png 768w\" sizes=\"auto, (max-width: 843px) 100vw, 843px\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Arbitrary_Condition_with_When\"><\/span>Arbitrary Condition with When<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>We can also use more than one checks to execute a block when the operator<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-5364 size-full\" title=\"Arbitrary Condition with When\" src=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-5-2.png\" alt=\"Arbitrary Condition with When\" width=\"843\" height=\"247\" srcset=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-5-2.png 843w, https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-5-2-300x88.png 300w, https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-5-2-768x225.png 768w\" sizes=\"auto, (max-width: 843px) 100vw, 843px\" \/><br \/>\nThere are several causes, but only one case that matches up will work as a respective block of code that executed. The comma added in the above example act as an OR operator.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Using_When_without_an_Argument\"><\/span>Using When without an Argument<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-5365 size-full\" title=\"Using When without an Argument\" src=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-6-2.png\" alt=\"Using When without an Argument\" width=\"849\" height=\"217\" srcset=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-6-2.png 849w, https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-6-2-300x77.png 300w, https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-6-2-768x196.png 768w\" sizes=\"auto, (max-width: 849px) 100vw, 849px\" \/><\/p>\n<p>We\u2019ve used \u2018when\u2019 with an argument. But when the real potential of when is we use when without an argument. Understand how it looks.<\/p>\n<p>Later, it acts as an if\/else block with class-level variable conditions.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Now_Compare_the_instance_with_When\"><\/span>Now, Compare the instance with When<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>We can check whether the given operator is an instance of a particular type at runtime by using the \u2018is\u2019 operator. The operator \u2018is\u2019 works similar to the instanceof operator in Java. Now use the \u2018is\u2019 and \u2018!is\u2019 operator inside when block. Get to know how <strong>Kotlin switch case with string<\/strong> works with an example.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-5366 size-full\" title=\"Now, Compare the instance with When\" src=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-7-2.png\" alt=\"Now, Compare the instance with When\" width=\"855\" height=\"171\" srcset=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-7-2.png 855w, https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-7-2-300x60.png 300w, https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/Untitled-7-2-768x154.png 768w\" sizes=\"auto, (max-width: 855px) 100vw, 855px\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Main_points_about_Kotlin_when\"><\/span>Main points about Kotlin when<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Java uses Switch conditional statements that operated with primitive data types, string class, and <strong>Kotlin switch enums<\/strong>. instead, Kotlin allows when to be used with any user-defined types. It makes it developer-friendly.<\/p>\n<p>Unlike Java, Kotlin\u2019s when can use with dynamic value like return type of functions.<br \/>\nAlso, check whether the given argument in collections uses the \u2018in\u2019 operator, which acts as contains.<\/p>\n<p>The else is mandatory if you\u2019re using when as an expression.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_of_a_wide_range_of_utility_functions\"><\/span>Example of a wide range of utility functions<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>In Kotlin, few simple utility functions are used for a simple task. Let\u2019s say if you want to get a minimum or maximum value in the range. Similarly, the average value of the sum of range, total count or value of the range, etc.<\/p>\n<p><strong>Check below Kotlin Functions<\/strong><\/p>\n<ul>\n<li>count()<\/li>\n<li>average()<\/li>\n<li>min()<\/li>\n<li>max()<\/li>\n<li>sum()<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In this blog, we have seen how powerful and useful the kotlin when the expression is. If you\u2019re using Kotlin, you find yourself using the when expression all the time. Connect with us if you\u2019re seeking to <a href=\"https:\/\/www.concettolabs.com\/kotlin-app-development\" target=\"_blank\" rel=\"nofollow\"><span style=\"text-decoration: underline;\"><strong>Hire Kotlin App Developers<\/strong><\/span><\/a> and switch to Kotlin when.<\/p>\n<style>\n      .blog-block-2{background:url(https:\/\/www.concettolabs.com\/blog\/wp-content\/uploads\/2020\/08\/2.png);background-position: center;background-repeat: no-repeat;background-size: cover;width: 100%;margin: 0 auto;padding: 43px 60px 80px;text-align: center; }      .blog-block-2 h3{font-size: 40px;color: #fff;line-height: 60px;text-align:center;}      .blog-block-2 h5{font-size: 20px;position: relative;padding: 0 10px;margin-bottom: 50px;text-align:center;color: #fff!important;}      .blog-block-2 h5:after{content:'';position: absolute;top: 10px!important;width: 100px;height: 2px;background-color: #fff;margin-left: 10px;}      .blog-block-2 h5:before{content:'';position: absolute;top: 10px!important;width: 100px;height: 2px;background-color: #fff;margin-left: -110px;}      a.blog-btn-new{padding:10px 30px;background: #fbbf13;color: #fff!important;font-size: 18px;border: 0;cursor: pointer; }      .blog-block-2 b{color: #fbbf13;font-weight: bold;}blog-block a:before{display:none;}.blog-block-2 p{text-align:center;color:#fff!important}<\/style>\n<p>&nbsp;<\/p>\n<div class=\"blog-block-2\">\n<h3><span class=\"ez-toc-section\" id=\"How_to_Replace_Switch_with_When_in_Kotlin\"><\/span>How to Replace Switch with <b>When in Kotlin?<\/b><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h5>That&#8217;s exactly what we do<\/h5>\n<p><a class=\"blog-btn-new\" href=\"https:\/\/www.concettolabs.com\/inquiry\" target=\"_blank\" rel=\"nofollow\">Contact Us<\/a><\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_71 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/#Switch\" title=\"Switch\">Switch<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/#Replace_Switch_Case_Kotlin_with_When\" title=\"Replace Switch Case Kotlin with When\">Replace Switch Case Kotlin with When<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/#Return_values_with_When_Block\" title=\"Return values with When Block\">Return values with When Block<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/#Arbitrary_Condition_with_When\" title=\"Arbitrary Condition with When\">Arbitrary Condition with When<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/#Using_When_without_an_Argument\" title=\"Using When without an Argument\">Using When without an Argument<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/#Now_Compare_the_instance_with_When\" title=\"Now, Compare the instance with When\">Now, Compare the instance with When<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/#Main_points_about_Kotlin_when\" title=\"Main points about Kotlin when\">Main points about Kotlin when<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/#Example_of_a_wide_range_of_utility_functions\" title=\"Example of a wide range of utility functions\">Example of a wide range of utility functions<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/#Summary\" title=\"Summary\">Summary<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/#How_to_Replace_Switch_with_When_in_Kotlin\" title=\"How to Replace Switch with When in Kotlin?\">How to Replace Switch with When in Kotlin?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n","protected":false},"excerpt":{"rendered":"<p>As a beginner, you might look for how the Kotlin switch statement works. If your background is working in C, Java, etc. then switching to Kotlin works best. There is no switch statement available in Kotlin; instead, it replaces the switch with the when expression. The switch is used as a two-state user interface element [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5371,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[3255],"tags":[2273,2275,2335,2336,2337,2338,2339],"class_list":["post-5357","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mobile-app","tag-hire-kotlin-app-developers","tag-kotlin-app-developers","tag-kotlin-switch-case","tag-kotlin-switch-case-with-string","tag-kotlin-switch-enums","tag-switch-case-kotlin","tag-switch-in-kotlin-android"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Replace Switch with When in Kotlin? | Concetto Labs<\/title>\n<meta name=\"description\" content=\"If you\u2019re using Kotlin, you find yourself using the when expression all the time. Connect with us if you\u2019re seeking to Hire Kotlin App Developers and switch to Kotlin when.\" \/>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Replace Switch with When in Kotlin? | Concetto Labs\" \/>\n<meta property=\"og:description\" content=\"If you\u2019re using Kotlin, you find yourself using the when expression all the time. Connect with us if you\u2019re seeking to Hire Kotlin App Developers and switch to Kotlin when.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/\" \/>\n<meta property=\"og:site_name\" content=\"concettolabs\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/manish.patel.710\" \/>\n<meta property=\"article:published_time\" content=\"2020-11-27T11:24:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-18T06:08:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/kotlin-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1170\" \/>\n\t<meta property=\"og:image:height\" content=\"540\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Manish Patel\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/withmanish\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Manish Patel\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/\",\"url\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/\",\"name\":\"How to Replace Switch with When in Kotlin? | Concetto Labs\",\"isPartOf\":{\"@id\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/kotlin-2.png\",\"datePublished\":\"2020-11-27T11:24:20+00:00\",\"dateModified\":\"2023-01-18T06:08:44+00:00\",\"author\":{\"@id\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/#\/schema\/person\/b27e0500ea2f536f7f0f5e7ab13566b9\"},\"description\":\"If you\u2019re using Kotlin, you find yourself using the when expression all the time. Connect with us if you\u2019re seeking to Hire Kotlin App Developers and switch to Kotlin when.\",\"breadcrumb\":{\"@id\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/#primaryimage\",\"url\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/kotlin-2.png\",\"contentUrl\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/kotlin-2.png\",\"width\":1170,\"height\":540,\"caption\":\"How to Replace Switch with When in Kotlin?\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Replace Switch with When in Kotlin?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/#website\",\"url\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/\",\"name\":\"concettolabs\",\"description\":\"Just another WordPress site\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/#\/schema\/person\/b27e0500ea2f536f7f0f5e7ab13566b9\",\"name\":\"Manish Patel\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2022\/03\/manish2-96x96.png\",\"contentUrl\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2022\/03\/manish2-96x96.png\",\"caption\":\"Manish Patel\"},\"description\":\"Manish Patel is a Co-Founder of Concetto Labs, a leading mobile app development company specialized in android and iOS app development. We provide a one-stop solution for all IT related services.\",\"sameAs\":[\"https:\/\/websitelaravel.concettoprojects.com\/blog\",\"https:\/\/www.facebook.com\/manish.patel.710\",\"https:\/\/in.linkedin.com\/in\/manishpatel2509\",\"https:\/\/x.com\/https:\/\/twitter.com\/withmanish\"],\"url\":\"https:\/\/websitelaravel.concettoprojects.com\/blog\/author\/manish-patel\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Replace Switch with When in Kotlin? | Concetto Labs","description":"If you\u2019re using Kotlin, you find yourself using the when expression all the time. Connect with us if you\u2019re seeking to Hire Kotlin App Developers and switch to Kotlin when.","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"How to Replace Switch with When in Kotlin? | Concetto Labs","og_description":"If you\u2019re using Kotlin, you find yourself using the when expression all the time. Connect with us if you\u2019re seeking to Hire Kotlin App Developers and switch to Kotlin when.","og_url":"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/","og_site_name":"concettolabs","article_author":"https:\/\/www.facebook.com\/manish.patel.710","article_published_time":"2020-11-27T11:24:20+00:00","article_modified_time":"2023-01-18T06:08:44+00:00","og_image":[{"width":1170,"height":540,"url":"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/kotlin-2.png","type":"image\/png"}],"author":"Manish Patel","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/withmanish","twitter_misc":{"Written by":"Manish Patel","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/","url":"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/","name":"How to Replace Switch with When in Kotlin? | Concetto Labs","isPartOf":{"@id":"https:\/\/websitelaravel.concettoprojects.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/#primaryimage"},"image":{"@id":"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/#primaryimage"},"thumbnailUrl":"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/kotlin-2.png","datePublished":"2020-11-27T11:24:20+00:00","dateModified":"2023-01-18T06:08:44+00:00","author":{"@id":"https:\/\/websitelaravel.concettoprojects.com\/blog\/#\/schema\/person\/b27e0500ea2f536f7f0f5e7ab13566b9"},"description":"If you\u2019re using Kotlin, you find yourself using the when expression all the time. Connect with us if you\u2019re seeking to Hire Kotlin App Developers and switch to Kotlin when.","breadcrumb":{"@id":"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/#primaryimage","url":"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/kotlin-2.png","contentUrl":"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2020\/11\/kotlin-2.png","width":1170,"height":540,"caption":"How to Replace Switch with When in Kotlin?"},{"@type":"BreadcrumbList","@id":"https:\/\/websitelaravel.concettoprojects.com\/blog\/how-to-replace-switch-with-when-in-kotlin\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/websitelaravel.concettoprojects.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Replace Switch with When in Kotlin?"}]},{"@type":"WebSite","@id":"https:\/\/websitelaravel.concettoprojects.com\/blog\/#website","url":"https:\/\/websitelaravel.concettoprojects.com\/blog\/","name":"concettolabs","description":"Just another WordPress site","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/websitelaravel.concettoprojects.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/websitelaravel.concettoprojects.com\/blog\/#\/schema\/person\/b27e0500ea2f536f7f0f5e7ab13566b9","name":"Manish Patel","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/websitelaravel.concettoprojects.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2022\/03\/manish2-96x96.png","contentUrl":"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-content\/uploads\/2022\/03\/manish2-96x96.png","caption":"Manish Patel"},"description":"Manish Patel is a Co-Founder of Concetto Labs, a leading mobile app development company specialized in android and iOS app development. We provide a one-stop solution for all IT related services.","sameAs":["https:\/\/websitelaravel.concettoprojects.com\/blog","https:\/\/www.facebook.com\/manish.patel.710","https:\/\/in.linkedin.com\/in\/manishpatel2509","https:\/\/x.com\/https:\/\/twitter.com\/withmanish"],"url":"https:\/\/websitelaravel.concettoprojects.com\/blog\/author\/manish-patel\/"}]}},"_links":{"self":[{"href":"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-json\/wp\/v2\/posts\/5357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-json\/wp\/v2\/comments?post=5357"}],"version-history":[{"count":1,"href":"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-json\/wp\/v2\/posts\/5357\/revisions"}],"predecessor-version":[{"id":8417,"href":"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-json\/wp\/v2\/posts\/5357\/revisions\/8417"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-json\/wp\/v2\/media\/5371"}],"wp:attachment":[{"href":"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-json\/wp\/v2\/media?parent=5357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-json\/wp\/v2\/categories?post=5357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/websitelaravel.concettoprojects.com\/blog\/wp-json\/wp\/v2\/tags?post=5357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}