两种方式调用多线程(及lambda使用)
public void Thread(){
//正常使用多线程
new Thread(new Runnable() {
@Override
public void run() {
Integer num = 20;
if (num==20){
String name = Thread.currentThread().getName();
System.out.println(name+"线程1");
}
}
}).start();
//使用 lambda 启动多线程 name 会打印线程方法
new Thread(()-> {
String name = Thread.currentThread().getName();
System.out.println(name+"线程2");
}
).start();
}
输出结果
Thread-1线程1
Thread-2线程2
判断长度
@Test标签:name,Thread,void,System,线程,多线程,表达式,lambda From: https://www.cnblogs.com/188221creat/p/16928601.html
public void Predicate(){
andMethod(s -> s.contains("W"),s -> s.contains("H"));
negateMethod(s -> s.length()<5);
}
//字符串中有W 或 H 吗
static void andMethod(Predicate<String> one , Predicate<String> two){
boolean week = one.or(two).test("Week");
System.out.println("and = " + week);
}
//判断长度是否小于5 negate(取反)
static void negateMethod(Predicate<String> predicate){
boolean leekSheet = predicate.negate().test("LeekSheet");
//boolean leekSheet = predicate.test("LeekSheet");
System.out.println("predicate = " + leekSheet);
}