jdk8的新特性

/**
*
* @author 
* 接口支持静态方法与默认方法
* default 有点抽象类了
* static 加入静态方法后,你以后的工具类就可以参考接口来设计
*
*/
public interface TestInterface {
    // 这个是默认方法
    default String get(String aa,String bb){
    System.out.println("我是jdk1.8默认实现方法...");
    return "";
}

String aa="2222";
// 这个是静态方法
static void staticmethod(){System.out.println("我是静态方法"+aa);}
}

lambda表达式的使用简化(遍历、差集、转换等)

它允许我们将一个函数当作方法的参数(传递函数),或者说把代码当作数据
比如: Arrays.asList( "a", "b", "d" ).forEach( e -> System.out.println( e ) );

Lambda表达式可以用逗号分隔的参数列表、->符号和功能语句块来表示
String separator = ",";
Arrays.asList( "a", "b", "d" ).forEach(
( String e ) -> System.out.print( e + separator ) );

Lambda表达式可能会引用类的成员或者局部变量(会被隐式地转变成final类型)

String separator = ",";
Arrays.asList( "a", "b", "d" ).forEach(
( String e ) -> System.out.print( e + separator ) );
等价于
final String separator = ",";
Arrays.asList( "a", "b", "d" ).forEach(
( String e ) -> System.out.print( e + separator ) );

//  差集

list1.stream().filter(t-> !list2.contains(t)).collect(Collectors.toList()) ;   list.stream().forEach(System.out::println);

//并集 不去重

list1.addAll(list2); System.out.println("并集 不去重"); list1.stream().forEach(System.out::println);

新的Base64API也支持URL和MINE的编码解码
Java 8新增加了很多方法支持并行的数组处理parallelSort()
java.util.concurrent.ConcurrentHashMap中加入了一些新方法来支持聚集操作

群交流(262200309)
原文地址:https://www.cnblogs.com/webster1/p/8652766.html