首页javastringJava Data Type - 如何替换字符串

Java Data Type - 如何替换字符串

我们想知道如何替换字符串。

The switch-expression uses a String type. If the switch-expression is null, a NullPointerException is thrown.

The case labels must be String literals. We cannot use String variables in the case labels.

The following is an example of using a String in a switch statement.

public class Main { public static void main(String[] args) { String status = "off"; switch (status) { case "on": System.out.println("Turn on"); case "off": System.out.println("Turn off"); break; default: System.out.println("Unknown command"); break; } } }