Java Control Statements
- Java if Statement
- Java Nested if Statement
- Java if-else-if Statement
- Java Switch Case
- Java Switch with String
- Java Nested Switch
- Java Simple for Loop
- Java for each Loop
- Java Nested for Loops
- Java while loop
- Java continue Statement with for Loop
- Java continue in do-while Loop
- Java break to Exit a for Loop
- Java break with Nested Loops
Java Switch Statement with String Example demonstrates how to use a switch statement with String in Java.
Java switch Statement with String Example
Beginning with JDK 7, we can use a string to control a switch statement.
The below example demonstrates the use of a string to control a switch statement.
package net.javaguides.corejava.controlstatements.switchcluase;
public class StringsSwitch {
public static void main(String args[]) {
String str = "two";
switch (str) {
case "one":
System.out.println("one");
break;
case "two":
System.out.println("two");
break;
case "three":
System.out.println("three");
break;
default:
System.out.println("no match");
break;
}
}
}
Output:
two
Control Statements
Java
Java Tutorial
Comments
Post a Comment