About 1,000,000 results
Open links in new tab
  1. java - Using values from a list as a case in a switch/case

    Oct 12, 2017 · switch (parameter) { case XXX: // some code here case YYY: // some code here } I want XXX to be name, and YYY to be gender, which both come from the ArrayList. I'm open to using if/else if this can't be done with switch/case. How can I do something like this? Thanks.

  2. Java switch Statement (With Examples) - Programiz

    The switch statement allows us to execute a block of code among many alternatives. In this tutorial, you will learn about the switch...case statement in Java with the help of examples.

  3. Switch Statements in Java - GeeksforGeeks

    Apr 11, 2025 · In simple words, the Java switch statement executes one statement from multiple conditions. It is an alternative to an if-else-if ladder statement. It provides an easy way to dispatch execution to different parts of the code based on the value of the expression.

  4. Java Switch Case Statement With Programming Examples

    Apr 1, 2025 · More often than that, Java Switch statement provides a better alternative than the various options available with Java if-else statements. Syntax: switch (expression){ case 1: //statement of case 1 break; case 2: //statement of case …

  5. Java Switch - W3Schools

    switch(expression) { case x: // code block break; case y: // code block break; default: // code block} This is how it works: The switch expression is evaluated once.

  6. Java Switch Case Example - Java Code Geeks

    Jan 10, 2014 · In this post, we feature a comprehensive Java Switch Case Example. Java provides decision making statements so as to control the flow of your program. The switch statement in java is the one that we will explain in this article.

  7. Using switch statement with a range of value in each case?

    In Java, is it possible to write a switch statement where each case contains more than one value? For example (though clearly the following code won't work): case 1 .. 5: System.out.println("testing case 1 to 5"); break; case 6 .. 10: System.out.println("testing case 6 to 10"); break;

  8. Java switch case with examples - CodeJava.net

    Mar 29, 2020 · This article helps you understand and use the switch case construct in Java with code examples. The switch-case construct is a flow control structure that tests value of a variable against a list of values.

  9. Java Switch Case Statement : Complete Tutorial With Examples

    Apr 16, 2025 · Below we share Syntax for java switch case with examples : [wp_ad_camp_3] Switch Case Java Example Program – 1. Output: Java switch case statement Example – 2. Output: Another Example Program – 3. Output: Java Switch case string example – 4. output: Learn More : When control comes to a switch construction, it …

  10. Java Switch Case Statement - Java Guides

    What is a Switch Case Statement? A switch statement evaluates a single expression and executes a block of code that matches the value of the expression. It simplifies code by eliminating the need for multiple if-else conditions and enhances readability. case value1: // code to be executed if expression equals value1 break; case value2:

Refresh