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!");
                break;
            case unix:
                System.out.println("You chose Unix!");
                break;
            case linux:
                System.out.println("You chose Linux!");
                break;
            case macintosh:
                System.out.println("You chose Macintosh!");
                break;
            default:
                System.out.println("I don't know your OS.");
                break;
        }
    }
}



           
         
    
  








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