Java Program to Implement switch statement on strings
To understand this example, you should have the knowledge of the following Java programming topics:
Example: Implement the switch statement on Strings
// Java Program to implement String on switch statements in Java
class Main {
public static void main(String[] args) {
// create a string
String language = "Java";
switch(language) {
case "Java":
System.out.println(language + " is famous for enterprise applications.");
break;
case "JavaScript":
System.out.println(language + " is famous for frontend and backend.");
break;
case "Python":
System.out.println(language + " is famous for ML and AI.");
break;
default:
System.out.println(language + " not found on record.");
break;
}
}
}
Output
Java is famous for enterprise applications.
In the above example, we have implemented the switch statement on Strings. This feature was introduced in Java 7.
Your builder path starts here. Builders don't just know how to code, they create solutions that matter.
Escape tutorial hell and ship real projects.
- Real-World Projects
- On-Demand Learning
- AI Mentor
- Builder Community