Enum with switch statement : Enum « Language Basics « Java

Enum with switch statement

import java.util.*;

enum OperatingSystems {
    windows, unix, linux, macintosh

public class EnumExample1 {
    public static void main(String args[])
        OperatingSystems os;

        os = OperatingSystems.windows;
        switch(os) {
            case windows:
                System.out.println("You chose Windows!");
            case unix:
                System.out.println("You chose Unix!");
            case linux:
                System.out.println("You chose Linux!");
            case macintosh:
                System.out.println("You chose Macintosh!");
                System.out.println("I don't know your OS.");


Related examples in the same category

1.How to use enum
2.Enum and GenericEnum and Generic
3.Media enumeration constantsMedia enumeration constants
4.Use an enum constructor.
5.Switching on Enum and Adding Methods to an Enum
6.An enumeration of apple varieties. An enumeration of apple varieties.
7.Use the built-in enumeration methods. Use the built-in enumeration methods.
8.Use an enum constructor, instance variable, and method. Use an enum constructor, instance variable, and method.
9.Java enum: Demonstrate ordinal(), compareTo(), and equals().Java enum: Demonstrate ordinal(), compareTo(), and equals().
10.Java enum: Creating an EnumJava enum: Creating an Enum
11.Java enum: EnumMap and Ant statusJava enum: EnumMap and Ant status
12.Java enum: Enum inside class
13.Java enum and varargs
14.This program demonstrates enumerated types
15.Shuffler Enum