Java 8: 新特性

PermGen在jdk1.8中已经完全被抛弃了,改用了Metaspace,在jdk1.8之前的版本中,PermGen还属于方法区,在1.8版本中用native memory来存储类、字段、方法的元信息。这意味着程序不会在抛出 java.lang.OutOfMemoryError: PermGen space 错误了,但是我们让然需要监控java堆内存的使用
,我们可以Metaspace得大小进行设置,默认是无限制,可以通过-XX:MaxMetaspaceSize=128m
设置Metaspace的大小。如果设置了Metaspace的大小(避免内存的浪费),当超过Metaspace的大小时,会抛出java.lang.OutOfMemoryError: Metadata space 这个新的异常。
参考jdk1.8 Metaspace

Parallel array sorting

parallelSort(byte[] a) 
parallelSort(byte[] a, int fromIndex, int toIndex) 
parallelSort(char[] a) 
parallelSort(char[] a, int fromIndex, int toIndex) 
parallelSort(double[] a) 
parallelSort(double[] a, int fromIndex, int toIndex) 
parallelSort(float[] a) 
parallelSort(float[] a, int fromIndex, int toIndex) 
parallelSort(int[] a) 
parallelSort(int[] a, int fromIndex, int toIndex) 
parallelSort(long[] a) 
parallelSort(long[] a, int fromIndex, int toIndex) 
parallelSort(short[] a) 
parallelSort(short[] a, int fromIndex, int toIndex) 
parallelSort(T[] a) 
parallelSort(T[] a, Comparator<? super T> c) 
parallelSort(T[] a, int fromIndex, int toIndex) 
parallelSort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c) 

Bulk Data Operations for Collections

public class CollectionTest {


    public static void main(String args[]){

        List<String> names = Arrays.asList("aaa", "bbb", "ccc"); 
        Person.init();


        List<Person> anyMatch = Person.people.stream().filter(p -> (names.stream()
                .anyMatch(p.name::contains))).collect(Collectors.toList()); 

        for(Person p : anyMatch){

            System.out.println(p.name);
        }

        //foreach区别传统的for循环
        Person.people.stream().forEach(action -> {

            System.out.println(action.name);
        });

        List<Person> reduced = Person.people.stream().filter
                (p -> names.stream().reduce(false, (Boolean b, String keyword) -> b || p.name.contains(keyword), (l, r) -> l | r))
                        .collect(Collectors.toList());

        for(Person p : reduced){

            System.out.println(p.name);
        }
    }

}

class Person{

    public String name;
    static List<Person> people = new ArrayList<Person>();

    public Person(String name){
        this.name = name;
    }
    static void init(){

        people.add(new Person("aaa"));
        people.add(new Person("bbb"));
        people.add(new Person("ccc"));
    }
}

New Date & Time API
java.util.DateSimpleDateFormatter都不是线程安全的,而jdk1.8中LocalDateLocalTimeDateTimeFormatterLocalDateTime,都是final类型的。意味着都是线程安全的。

LocalDate date = LocalDate.now();   //当前日期
LocalTime time = LocalTime.now();   //当前时间
LocalDateTime time_ = LocalDateTime.now(); //当前的日期时间
LocalDateTime time_ = LocalDateTime.now().withNano(0);//清除毫秒数
// 根据年月日取日期,12月就是12,不是变态的从0开始计算月份
LocalDate crischristmas = LocalDate.of(2014, 12, 25); // -> 2014-12-25
//java也提供了format的类
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值