{"id":25537837,"date":"2022-08-14T17:07:23","date_gmt":"2022-08-14T11:37:23","guid":{"rendered":"https:\/\/entri.app\/blog\/?p=25537837"},"modified":"2022-11-23T14:46:19","modified_gmt":"2022-11-23T09:16:19","slug":"what-is-switch-case-in-java-and-how-to-use","status":"publish","type":"post","link":"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/","title":{"rendered":"What is Switch Case in Java and How to Use"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_79_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69e8405b055ee\" class=\"ez-toc-cssicon-toggle-label\"><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><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69e8405b055ee\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#Use_of_Switch_Case_in_Java\" >Use of Switch Case in Java<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#Switch_statement_in_Java_and_how_does_it_work\" >Switch statement in Java and how does it work?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#Syntax_of_Switch_Case_Program_in_Java1\" >Syntax of Switch Case Program in Java[1]<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#Execution_while_Omitting_the_Break_Statement\" >Execution while Omitting the Break Statement<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#More_examples\" >More examples:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<div class=\"detail-banner article-banner-details banner-height\">\n<div class=\"article-info test-class\"><\/div>\n<div class=\"img-bg-colr\"><\/div>\n<\/div>\n<div class=\"info-details\">\n<div id=\"articleLongDescription\">\n<article class=\"desig_author empty-text\">The switch statement in java or switch case in java is a multi-way branch statement. Based on the value of the expression given, different parts of code can be executed quickly. The given expression can be of a primitive data type such as int, char, short, byte, and char. With JDK7, the switch case in java works with the string and wrapper class and enumerated data type (enum in java).<\/article>\n<article><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25520910 size-full\" src=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square.png\" alt=\"Python and Machine Learning Square\" width=\"345\" height=\"345\" srcset=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square.png 345w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-300x300.png 300w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-150x150.png 150w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-24x24.png 24w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-48x48.png 48w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-96x96.png 96w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-75x75.png 75w\" sizes=\"auto, (max-width: 345px) 100vw, 345px\" \/><\/a><\/article>\n<article class=\"desig_author empty-text\">\n<article>\n<h2 id=\"use_of_switch_case_in_java\"><span class=\"ez-toc-section\" id=\"Use_of_Switch_Case_in_Java\"><\/span><strong>Use of Switch Case in Java<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The switch case in java is used to select one of many code blocks for execution.<\/p>\n<p>Break keyword: As java reaches a break keyword, the control breaks out of the switch block. The execution of code stops on encountering this keyword, and the case testing inside the block ends as the match is found. A lot of execution time can be saved because it ignores the rest of the code&#8217;s execution when there is a break.<\/p>\n<p>Default keyword: The keyword is used to specify the code executed when the expression does not match any test case.<\/p>\n<p style=\"text-align: center;\"><strong><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\">Learn Coding in your Language! Enroll Here!<\/a><\/strong><\/p>\n<\/article>\n<article>\n<h2 id=\"how_does_the_switch_statement_work\"><span class=\"ez-toc-section\" id=\"Switch_statement_in_Java_and_how_does_it_work\"><\/span><strong>Switch statement in Java and how does it work?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>This is how switch case in Java work:<\/p>\n<p>The switch case in Java works like an\u00a0if-else\u00a0ladder, i.e., multiple conditions can be checked at once. Switch is provided with an expression that can be a constant or literal expression that can be evaluated. The value of the expression is matched with each test case till a match is found. If there is no match, the default keyword, if specified- the associated code executes. Otherwise, the code specified for the matched test case is executed.<\/p>\n<p>There are some things to be remembered while using switch case in java:<\/p>\n<ul>\n<li>Two cases cannot have the same value<\/li>\n<li>The data type of variable in the switch needs to be the same as all test cases&#8217; values.<\/li>\n<li>The value for the cases needs to be literal or constant but not a variable. For example:<\/li>\n<\/ul>\n<p>Valid expressions: switch (1+2+3+4) , switch(1*2+3%4)<\/p>\n<p>Invalid expressions: switch(ef+gh), switch(e+f+g)<\/p>\n<ul>\n<li>The break statement is used to terminate the statement sequence inside the switch.<\/li>\n<li>The test case values need not be in order (ascending or descending). It can occur as per requirement.<\/li>\n<li>If the break statement is omitted, the execution will continue into the next test case.<\/li>\n<li>The default statement can appear anywhere inside the switch block, but a break statement should follow it if the default is not in the end.<\/li>\n<li>Nesting is allowed, but it makes the program more complex.<\/li>\n<\/ul>\n<p>For example, the code below uses the monthly number to calculate the month name:<\/p>\n<p>public class Main {<\/p>\n<p>public static void main(String[] args) {<\/p>\n<p>int month = 4;<\/p>\n<p>switch (month) {<\/p>\n<p>case 1:<\/p>\n<p>System.out.println(&#8220;January&#8221;);<\/p>\n<p>break;<\/p>\n<p>case 2:<\/p>\n<p>System.out.println(&#8220;February&#8221;);<\/p>\n<p>break;<\/p>\n<p>case 3:<\/p>\n<p>System.out.println(&#8220;March&#8221;);<\/p>\n<p>break;<\/p>\n<p>case 4:<\/p>\n<p>System.out.println(&#8220;April&#8221;);<\/p>\n<p>break;<\/p>\n<p>case 5:<\/p>\n<p>System.out.println(&#8220;May&#8221;);<\/p>\n<p>break;<\/p>\n<p>case 6:<\/p>\n<p>System.out.println(&#8220;June&#8221;);<\/p>\n<p>break;<\/p>\n<p>default: System.out.println(&#8220;In next half&#8221;);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<h4>Output:<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/SwitchStatement.png\" alt=\"SwitchStatement.\" width=\"702\" height=\"160\" \/><\/p>\n<\/article>\n<article>\n<h2 id=\"syntax_of_switch_case_in_java1\"><span class=\"ez-toc-section\" id=\"Syntax_of_Switch_Case_Program_in_Java1\"><\/span><strong>Syntax of Switch Case Program in Java[1]<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The syntax of the switch statement in Java is as follows:<\/p>\n<p>switch(expression)<\/p>\n<p>{<\/p>\n<p>\/\/ The switch block has case statements whose values must be of the same type of expression<\/p>\n<p>case value1 :<\/p>\n<p>\/\/ Code statement to be executed<\/p>\n<p>break; \/\/ break is optional<\/p>\n<p>case value2 :<\/p>\n<p>\/\/ Code statement to be executed<\/p>\n<p>break; \/\/ break is optional<\/p>\n<p>\/\/ There can be several case statements<\/p>\n<p>\/\/ When none of the cases is true, a default statement is used, and no break is needed in the default case.<\/p>\n<p>default :<\/p>\n<p>\/\/ Code statement to be executed<\/p>\n<p>}<\/p>\n<\/article>\n<article>\n<h2 id=\"execution_while_omitting_the_break_statement\"><span class=\"ez-toc-section\" id=\"Execution_while_Omitting_the_Break_Statement\"><\/span><strong>Execution while Omitting the Break Statement<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Since the break statement is optional, we can omit it. On execution without a break statement, control will continue into the next case. There can be multiple cases without a break statement between them as it is desirable in some cases, such as the given one. This code displays whether a month has 30, 31, or 28 days:<\/p>\n<p>Java program to demonstrate switch case with multiple cases without break statements.<\/p>\n<p>public class Main {<\/p>\n<p>public static void main(String[] args) {<\/p>\n<p>int month = 4;<\/p>\n<p>switch (month) {<\/p>\n<p>case 1:<\/p>\n<p>case 3:<\/p>\n<p>case 5:<\/p>\n<p>case 7:<\/p>\n<p>case 8:<\/p>\n<p>case 10:<\/p>\n<p>case 12:<\/p>\n<p>System.out.println(&#8220;31 days&#8221;);<\/p>\n<p>break;<\/p>\n<p>case 2:\u00a0 System.out.println(&#8220;28 days&#8221;);<\/p>\n<p>break;<\/p>\n<p>case 4:<\/p>\n<p>case 6:<\/p>\n<p>case 9:<\/p>\n<p>case 11:<\/p>\n<p>System.out.println(&#8220;30 days&#8221;);<\/p>\n<p>break;<\/p>\n<p>default: System.out.println(&#8220;Error&#8221;);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<h4>Output:<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/OmittingtheBreakStatement.png\" alt=\"OmittingtheBreakStatement\" width=\"702\" height=\"181\" \/><\/p>\n<\/article>\n<article>\n<p style=\"text-align: center;\"><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><strong>Learn to code from industry experts! Enroll here<\/strong><\/a><\/p>\n<h2 id=\"more_examples\"><span class=\"ez-toc-section\" id=\"More_examples\"><\/span><strong>More examples:<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li>\n<h3><strong>Nested Switch Case in Java<\/strong><\/h3>\n<\/li>\n<\/ul>\n<p>A switch case can be used as a part of an outer switch&#8217;s statement sequence. This is known as a nested switch case in java. As a switch case defines its block, the case constraints in the inner switch do not conflict with those in the outer switch. Here is a Java program to demonstrate nested switch case statement:<\/p>\n<p>public class Main {<\/p>\n<p>public static void main(String[] args)<\/p>\n<p>{<\/p>\n<p>String Branch = &#8220;CS&#8221;;<\/p>\n<p>int year = 1;<\/p>\n<p>switch (year) {<\/p>\n<p>case 1:<\/p>\n<p>System.out.println(&#8220;elective courses : Advance Maths, Algebra&#8221;);<\/p>\n<p>break;<\/p>\n<p>case 2:<\/p>\n<p>switch (Branch)<\/p>\n<p>{<\/p>\n<p>case &#8220;CS&#8221;:<\/p>\n<p>case &#8220;ECE&#8221;:<\/p>\n<p>System.out.println(&#8220;elective courses : ML, Big Data&#8221;);<\/p>\n<p>break;<\/p>\n<p>case &#8220;IT&#8221;:<\/p>\n<p>System.out.println(&#8220;elective courses : Software Engineering&#8221;);<\/p>\n<p>break;<\/p>\n<p>default:<\/p>\n<p>System.out.println(&#8220;Elective courses : English&#8221;);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<h4>Output:<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/NestedSwitchCase.png\" alt=\"NestedSwitchCase\" width=\"709\" height=\"160\" \/><\/p>\n<ul>\n<li>\n<h3><strong>Java\u00a0Program\u00a0to\u00a0Demonstrate\u00a0the\u00a0Use\u00a0of\u00a0Enum\u00a0in\u00a0Switch\u00a0Statement<\/strong><\/h3>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>Code:<\/p>\n<p>public class Main {<\/p>\n<p>public enum Day {\u00a0 S, M, T, W, Th, F, St\u00a0 }<\/p>\n<p>public static void main(String args[])<\/p>\n<p>{<\/p>\n<p>Day[] DayNow = Day.values();<\/p>\n<p>for (Day Now : DayNow)<\/p>\n<p>{<\/p>\n<p>switch (Now)<\/p>\n<p>{<\/p>\n<p>case S:<\/p>\n<p>System.out.println(&#8220;Sunday&#8221;);<\/p>\n<p>break;<\/p>\n<p>case M:<\/p>\n<p>System.out.println(&#8220;Monday&#8221;);<\/p>\n<p>break;<\/p>\n<p>case T:<\/p>\n<p>System.out.println(&#8220;Tuesday&#8221;);<\/p>\n<p>break;<\/p>\n<p>case W:<\/p>\n<p>System.out.println(&#8220;Wednesday&#8221;);<\/p>\n<p>break;<\/p>\n<p>case Th:<\/p>\n<p>System.out.println(&#8220;Thursday&#8221;);<\/p>\n<p>break;<\/p>\n<p>case F:<\/p>\n<p>System.out.println(&#8220;Friday&#8221;);<\/p>\n<p>break;<\/p>\n<p>case St:<\/p>\n<p>System.out.println(&#8220;Saturday&#8221;);<\/p>\n<p>break;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/EnuminSwitchStatement%20.png\" alt=\"EnuminSwitchStatement%20\" width=\"703\" height=\"169\" \/><\/p>\n<ul>\n<li>\n<h3><strong>Java\u00a0Program\u00a0to\u00a0Demonstrate\u00a0the\u00a0Use\u00a0of\u00a0Wrapper\u00a0class\u00a0in\u00a0Switch\u00a0Statement<\/strong><\/h3>\n<\/li>\n<\/ul>\n<p>Code:<\/p>\n<p>public class Main {<\/p>\n<p>public static void main(String args[])<\/p>\n<p>{<\/p>\n<p>Integer age = 18;<\/p>\n<p>switch (age)<\/p>\n<p>{<\/p>\n<p>case (16):<\/p>\n<p>System.out.println(&#8220;You are not an adult.&#8221;);<\/p>\n<p>break;<\/p>\n<p>case (18):<\/p>\n<p>System.out.println(&#8220;You are an adult.&#8221;);<\/p>\n<p>break;<\/p>\n<p>case (65):<\/p>\n<p>System.out.println(&#8220;You are senior citizen.&#8221;);<\/p>\n<p>break;<\/p>\n<p>default:<\/p>\n<p>System.out.println(&#8220;Please give the valid age.&#8221;);<\/p>\n<p>break;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<h4>Output:<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/WrapperclassinSwitchState.png\" alt=\"WrapperclassinSwitchState\" width=\"703\" height=\"183\" \/><\/p>\n<\/article>\n<article>\n<h2 id=\"conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><strong>Conclusion<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The switch case program in java executes one statement from multiple ones. Thus, it is like an if-else-if ladder statement. It works with a lot of data types. The switch statement in java is used to test the equality of a variable against several values specified in the test cases.<\/p>\n<p><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25520910 size-full\" src=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square.png\" alt=\"Python and Machine Learning Square\" width=\"345\" height=\"345\" srcset=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square.png 345w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-300x300.png 300w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-150x150.png 150w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-24x24.png 24w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-48x48.png 48w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-96x96.png 96w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-75x75.png 75w\" sizes=\"auto, (max-width: 345px) 100vw, 345px\" \/><\/a><\/p>\n<p>Java is one of the most widely used\u00a0programming languages used today. And if you wish to make a career out of it, mastering it is definitely the first step.<\/p>\n<p style=\"text-align: center;\"><strong><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\">Grab the opportunity to learn Python with Entri! Click Here<\/a><\/strong><\/p>\n<\/article>\n<\/article>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The switch statement in java or switch case in java is a multi-way branch statement. Based on the value of the expression given, different parts of code can be executed quickly. The given expression can be of a primitive data type such as int, char, short, byte, and char. With JDK7, the switch case in [&hellip;]<\/p>\n","protected":false},"author":111,"featured_media":25538031,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[802,1882],"tags":[],"class_list":["post-25537837","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-articles","category-java-programming"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is Switch Case in Java and How to Use - Entri Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is Switch Case in Java and How to Use - Entri Blog\" \/>\n<meta property=\"og:description\" content=\"The switch statement in java or switch case in java is a multi-way branch statement. Based on the value of the expression given, different parts of code can be executed quickly. The given expression can be of a primitive data type such as int, char, short, byte, and char. With JDK7, the switch case in [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/\" \/>\n<meta property=\"og:site_name\" content=\"Entri Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/entri.me\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-14T11:37:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-23T09:16:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/08\/What-is-Switch-Case-in-Java-and-How-to-Use-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"820\" \/>\n\t<meta property=\"og:image:height\" content=\"615\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Feeba Mahin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@entri_app\" \/>\n<meta name=\"twitter:site\" content=\"@entri_app\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Feeba Mahin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/\"},\"author\":{\"name\":\"Feeba Mahin\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36\"},\"headline\":\"What is Switch Case in Java and How to Use\",\"datePublished\":\"2022-08-14T11:37:23+00:00\",\"dateModified\":\"2022-11-23T09:16:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/\"},\"wordCount\":1098,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/entri.app\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/08\/What-is-Switch-Case-in-Java-and-How-to-Use-1.png\",\"articleSection\":[\"Articles\",\"Java Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/\",\"url\":\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/\",\"name\":\"What is Switch Case in Java and How to Use - Entri Blog\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/08\/What-is-Switch-Case-in-Java-and-How-to-Use-1.png\",\"datePublished\":\"2022-08-14T11:37:23+00:00\",\"dateModified\":\"2022-11-23T09:16:19+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#primaryimage\",\"url\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/08\/What-is-Switch-Case-in-Java-and-How-to-Use-1.png\",\"contentUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/08\/What-is-Switch-Case-in-Java-and-How-to-Use-1.png\",\"width\":820,\"height\":615,\"caption\":\"What is Switch Case in Java and How to Use\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/entri.app\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Entri Skilling\",\"item\":\"https:\/\/entri.app\/blog\/category\/entri-skilling\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Java Programming\",\"item\":\"https:\/\/entri.app\/blog\/category\/entri-skilling\/java-programming\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"What is Switch Case in Java and How to Use\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/entri.app\/blog\/#website\",\"url\":\"https:\/\/entri.app\/blog\/\",\"name\":\"Entri Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/entri.app\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/entri.app\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/entri.app\/blog\/#organization\",\"name\":\"Entri App\",\"url\":\"https:\/\/entri.app\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png\",\"contentUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png\",\"width\":989,\"height\":446,\"caption\":\"Entri App\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/entri.me\/\",\"https:\/\/x.com\/entri_app\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36\",\"name\":\"Feeba Mahin\",\"url\":\"https:\/\/entri.app\/blog\/author\/feeba123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is Switch Case in Java and How to Use - Entri Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/","og_locale":"en_US","og_type":"article","og_title":"What is Switch Case in Java and How to Use - Entri Blog","og_description":"The switch statement in java or switch case in java is a multi-way branch statement. Based on the value of the expression given, different parts of code can be executed quickly. The given expression can be of a primitive data type such as int, char, short, byte, and char. With JDK7, the switch case in [&hellip;]","og_url":"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/","og_site_name":"Entri Blog","article_publisher":"https:\/\/www.facebook.com\/entri.me\/","article_published_time":"2022-08-14T11:37:23+00:00","article_modified_time":"2022-11-23T09:16:19+00:00","og_image":[{"width":820,"height":615,"url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/08\/What-is-Switch-Case-in-Java-and-How-to-Use-1.png","type":"image\/png"}],"author":"Feeba Mahin","twitter_card":"summary_large_image","twitter_creator":"@entri_app","twitter_site":"@entri_app","twitter_misc":{"Written by":"Feeba Mahin","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#article","isPartOf":{"@id":"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/"},"author":{"name":"Feeba Mahin","@id":"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36"},"headline":"What is Switch Case in Java and How to Use","datePublished":"2022-08-14T11:37:23+00:00","dateModified":"2022-11-23T09:16:19+00:00","mainEntityOfPage":{"@id":"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/"},"wordCount":1098,"commentCount":0,"publisher":{"@id":"https:\/\/entri.app\/blog\/#organization"},"image":{"@id":"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#primaryimage"},"thumbnailUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/08\/What-is-Switch-Case-in-Java-and-How-to-Use-1.png","articleSection":["Articles","Java Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/","url":"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/","name":"What is Switch Case in Java and How to Use - Entri Blog","isPartOf":{"@id":"https:\/\/entri.app\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#primaryimage"},"image":{"@id":"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#primaryimage"},"thumbnailUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/08\/What-is-Switch-Case-in-Java-and-How-to-Use-1.png","datePublished":"2022-08-14T11:37:23+00:00","dateModified":"2022-11-23T09:16:19+00:00","breadcrumb":{"@id":"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#primaryimage","url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/08\/What-is-Switch-Case-in-Java-and-How-to-Use-1.png","contentUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/08\/What-is-Switch-Case-in-Java-and-How-to-Use-1.png","width":820,"height":615,"caption":"What is Switch Case in Java and How to Use"},{"@type":"BreadcrumbList","@id":"https:\/\/entri.app\/blog\/what-is-switch-case-in-java-and-how-to-use\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/entri.app\/blog\/"},{"@type":"ListItem","position":2,"name":"Entri Skilling","item":"https:\/\/entri.app\/blog\/category\/entri-skilling\/"},{"@type":"ListItem","position":3,"name":"Java Programming","item":"https:\/\/entri.app\/blog\/category\/entri-skilling\/java-programming\/"},{"@type":"ListItem","position":4,"name":"What is Switch Case in Java and How to Use"}]},{"@type":"WebSite","@id":"https:\/\/entri.app\/blog\/#website","url":"https:\/\/entri.app\/blog\/","name":"Entri Blog","description":"","publisher":{"@id":"https:\/\/entri.app\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/entri.app\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/entri.app\/blog\/#organization","name":"Entri App","url":"https:\/\/entri.app\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png","contentUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png","width":989,"height":446,"caption":"Entri App"},"image":{"@id":"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/entri.me\/","https:\/\/x.com\/entri_app"]},{"@type":"Person","@id":"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36","name":"Feeba Mahin","url":"https:\/\/entri.app\/blog\/author\/feeba123\/"}]}},"_links":{"self":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25537837","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/users\/111"}],"replies":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/comments?post=25537837"}],"version-history":[{"count":6,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25537837\/revisions"}],"predecessor-version":[{"id":25548006,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25537837\/revisions\/25548006"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/media\/25538031"}],"wp:attachment":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/media?parent=25537837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/categories?post=25537837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/tags?post=25537837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}