-
接口中可以定义和实现静态和default方法
-
Lambda表达式
-
①ConcurrentHashMap不再使用JDK7的多段锁机制去设置值(将每个数据分成很多段,每段都会上一把锁;当一个线程操作某个段的数据的时候,其他段的数据可以被其他线程操作);
而是采用先CAS算法,如果CAS失败就使用synchronized对添加的对象上锁;
②底层由原来的数组+链表变为数组+链表/红黑树;链表变为红黑树的触发条件:数组长度>64,且链表长度超过8(这点HashMap与其一致)
③优化了统计集合内元素数量的方式
-
HashMap的底层优化如上第②点;JDK8以前采取头插法,JDK8后就采取尾插法
-
Map等集合新增专门的遍历方法forEach( )
-
新增元注解@Repeatable,其修饰的注解可同时作用于一个对象多次,每次的作用可以不同
注解上下文扩展:可作用于:局部变量、泛型类和方法异常等等
-
新增类Stream,其许多方法可以用于简化对集合框架的处理
如下是调用了Stream中的stream().sorted( )方法,指定了一个Comparator.reverseOrder()作为参数,表示降序排序;排好序的隔行输出,原样顺序的隔空格输出;
class Scratch {
public static void main(String[] args) throws Exception {
//在此编写你的代码
BufferedReader reader =new BufferedReader(new InputStreamReader(System.in));
String snum1 = reader.readLine();
String snum2 = reader.readLine();
String snum3 = reader.readLine();
String snum4 = reader.readLine();
String snum5 = reader.readLine();
int num1 = Integer.parseInt(snum1);
int num2 = Integer.parseInt(snum2);
int num3 = Integer.parseInt(snum3);
int num4 = Integer.parseInt(snum4);
int num5 = Integer.parseInt(snum5);
List<Integer> arrayList = new ArrayList<>();
arrayList.add(num1);
arrayList.add(num2);
arrayList.add(num3);
arrayList.add(num4);
arrayList.add(num5);
Stream<Integer> sorted = arrayList.stream().sorted(Comparator.reverseOrder());
sorted.forEach((value) -> {
System.out.println(value);
});
System.out.println();
for (Integer integer : arrayList) {
System.out.print(integer + " ");
}
}
}
输出结果:
-
Arrays新增了排序方法parallelsort( )方法,功能与sort( )相同,但是在底层上充分利用了CPU并行的能力来提高排序运算的性能
-
JVM的运行时数据区中的方法区: 在JDK8以前是永生代去实现方法区,JDK8以后弃用了永生代而采用基于本地内存的元空间去实现方法区