极速网站推广专家,a4网站建设,中国十大网站有哪些,宿迁房产中介新特性#xff1a; Lambda表达式: #xff08;语法三要素#xff1a;参数、箭头、代码#xff09; JDK1.8引入的一种新语法Lambda表达式,它简化了匿名内部类的使用和提高代码的可读性。
/**正常写法创建Runable**/
Runnable runnable new Runnable() {Overridepublic voi…新特性 Lambda表达式: 语法三要素参数、箭头、代码 JDK1.8引入的一种新语法Lambda表达式,它简化了匿名内部类的使用和提高代码的可读性。
/**正常写法创建Runable**/
Runnable runnable new Runnable() {Overridepublic void run() {System.out.println(*************);}
};/**Lambda表达式写法*/
Runnable runnable () - System.out.println(*************); 接口提供默认方法和静态方法:
public interface UserService {/*** 默认方法*/default void add(){System.out.println(add);};/*** 静态方法* param id* return*/public static User getUser(String id){return new User();};
} Stream API : JDK1.8引入的一种新抽象流提供一种新的处理数据方式对集合或数据元素进行函数式编程数据处理所有 Collection 集合都可以通过 stream 默认方法获取流。 ListString list Arrays.asList(ASDSFSDSF,NBDS,WKEKRERE,BC8D);//通过stream流过滤列表中长度等4的字符串列表ListString newList list.stream().filter(pre-pre.length()4).collect(Collectors.toList());//通过stream流把列表内容转换小写并返回一个新的列表ListString toLowerCaseList list.stream().map(String::toLowerCase).collect(Collectors.toList());//获取集合长度long count list.stream().count();//获取集合第1个元素OptionalString first list.stream().findFirst(); 函数试接口 : 1、自定义函数试接口
FunctionalInterface
public interface MyFunctionalInterface {int add(int a,int b);
}
//调用
MyFunctionalInterface myFunctionalInterface (a,b)- ab;
int a myFunctionalInterface.add(5,2);
System.out.println(a);2、PredicateT判断型接口输入一个参数T返回一个布尔值 PredicateString isEmpty p - p.isEmpty();// 输出: falseSystem.out.println(isEmpty.test(abc)); 3、FunctionT,R函数试接口有输入参数T和返回结果R用于执行一些转换逻辑。
FunctionInteger, Integer function (Integer i) - i * i;
// 输出: 100
System.out.println(function.apply(10)); 4、SupplierT供给型接口无参数返回数据类型T。 5、ConsumerT消费型接口有参数T无返回值。
public class User {public void follow(final String str) {System.out.println(Following the str);}
}ConsumerString follow user :: follow;
follow.accept(Consumer....); 方法引用 : 1、构造器引用: ClassName::new 2、类的静态方法引用: ClassName::staticMethodName 3、对象的实例方法引用: object::methodName 4、特定类型的实例方法引用:TypeName::methodName LocalDate API : 1、LocalDate : 年月日; 2、LocalTime : 时分秒; 3、LocalDateTime : 年月日时分秒; 4、Period : 两个日期之间的时间间隔; 5、Duration : 两个时间之间的持续时间;