Java 实例 - 标签(Label)
Java 教程
· 2019-02-10 17:12:32
Java 中的标签是为循环设计的,是为了在多重循环中方便的使用break 和coutinue 。
以下实例当在循环中使用 break 或 continue 循环时跳到指定的标签处:
Main.java 文件
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 <= max; i++) {
int length = substring.length();
int j = i;
int k = 0;
while (length-- != 0) {
if(strSearch.charAt(j++) != substring.charAt(k++)){
continue testlbl;
}
}
found = true;
break testlbl;
}
if (found) {
System.out.println("发现子字符串。");
}
else {
System.out.println("字符串中没有发现子字符串。");
}
}
}
以上代码运行输出结果为:
发现子字符串。
点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html
Java并发编程的艺术
方腾飞、魏鹏、程晓明 / 机械工业出版社 / 2015-7-1 / 59.00元
并发编程领域的扛鼎之作,作者是阿里和1号店的资深Java技术专家,对并发编程有非常深入的研究,《Java并发编程的艺术》是他们多年一线开发经验的结晶。本书的部分内容在出版早期发表在Java并发编程网和InfoQ等技术社区,得到了非常高的评价。它选取了Java并发编程中最核心的技术进行讲解,从JDK源码、JVM、CPU等多角度全面剖析和讲解了Java并发编程的框架、工具、原理和方法,对Java并发编......一起来看看 《Java并发编程的艺术》 这本书的介绍吧!
RGB HSV 转换
RGB HSV 互转工具
RGB CMYK 转换工具
RGB CMYK 互转工具