About 106,000 results
Open links in new tab
  1. Switch on Enum in Java - Stack Overflow

    Why can't you switch on an enum in Java? It seems simple enough to do and would make for some convenient code. Also this question could apply to String's. You can switch on a char, …

  2. Java using enum with switch statement - Stack Overflow

    Nov 13, 2011 · There's a couple of ways you can go about this: Determine the enum value represented by the int value and then switch on the enum value. SEVEN_DAY, …

  3. Usage of Enum and Switch Keyword in Java - GeeksforGeeks

    Feb 28, 2022 · We can use also use Enum keyword with Switch statement. We can use Enum in Switch case statement in Java like int primitive. Below are some examples to show working of …

  4. Java Switch on Enum Value - Stack Overflow

    Dec 9, 2018 · Create a get method inside of your Week enum in order to obtain a Week by a giving string, for example: public enum Week { ... public Week getWeek(String key) { ... logic …

  5. How to Switch on Enum in Java - Delft Stack

    Feb 2, 2024 · We will go through two ways to use the switch statement with enum. In the example, we create an enum inside the SwitchEnum class and name it Days. It holds seven …

  6. A Java enum switch/case statement example - alvinalexander.com

    May 18, 2022 · Java enum FAQ: Can you share a Java enum switch example, i.e., how to use an enum with a Java switch statement? In my earlier Java enum examples tutorial, I …

  7. Switch case with enum in Java - Tpoint Tech

    Enum can be used similarly to an int primitive in a Java Switch case statement. The following examples show how an Enum with something like a Switch statement functions.

  8. How to use enum in Java switch statement - LabEx

    Learn how to effectively use enums with switch statements in Java, explore practical patterns, and improve code readability and type safety in your Java programming projects.

  9. Why Can't You Use Switch Statement with Enums in Java?

    In Java, it is indeed possible to use enums in switch statements since enums are constants and can be treated similarly to integers. However, if you've experienced issues, these are often …

  10. Switch on enums in Java 14 – Memoirs of a Software developer

    May 5, 2020 · With the introduction of switch expressions in Java 14, code using enums in switch expressions is more robust. The compiler checks if all possible values have been handled and …

  11. Some results have been removed
Refresh