Using string literals in switch statements - Java Language Basics

Java examples for Language Basics:switch

Description

Using string literals in switch statements

Demo Code

public class Main {

  public static void main(String[] args) {
    for (String argument : args) {
      switch (argument) {
      case "-verbose":
      case "-v":
        System.out.println("-v");
        break;/*  w ww .j  ava2  s. c  o  m*/
      case "-log":
        System.out.println("-log");
        break;
      case "-help":
        System.out.println("-help");
        break;
      default:
        System.out.println("Illegal command line argument");
      }
    }
  }
}

Related Tutorials