Java 中的标签是为循环设计的,是为了在多重循环中方便的使用 break 和coutinue 。
以下实例当在循环中使用 break 或 continue 循环时跳到指定的标签处:
public class Main {
public static void main(String[] args) {
String strSearch = "This is the string in which you have to search for a substring.";
String substring = "substring";
boolean found = false;
int max = strSearch.length() - substring.length();
testlbl:
for (int i = 0; i
以上代码运行输出结果为:
发现子字符串。
自学教程