Java Tutorials for jdk8复习

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/everlasting_188/article/details/86662499

1、并发类

  • BlockingQueue defines a first-in-first-out data structure that blocks or times out when you attempt to add to a full queue, or retrieve from an empty queue.

    阻塞队列,线程池使用到了

  • ConcurrentMap is a subinterface of java.util.Map that defines useful atomic operations. These operations remove or replace a key-value pair only if the key is present, or add a key-value pair only if the key is absent. Making these operations atomic helps avoid synchronization. The standard general-purpose implementation of ConcurrentMap is ConcurrentHashMap, which is a concurrent analog of HashMap.

     HashMap的并发实现ConcurrentHashMap,

    TreeMap的并发实现ConcurrentSkipListMap,

2、集合的算法部分

Collections class provides five algorithms for doing routine data manipulation on List objects, all of which are pretty straightforward:

  • reverse — reverses the order of the elements in a List.
  • fill — overwrites every element in a List with the specified value. This operation is useful for reinitializing a List.
  • copy — takes two arguments, a destination List and a source List, and copies the elements of the source into the destination, overwriting its contents. The destination List must be at least as long as the source. If it is longer, the remaining elements in the destination List are unaffected.
  • swap — swaps the elements at the specified positions in a List.
  • addAll — adds all the specified elements to a Collection. The elements to be added may be specified individually or as an array.

集合提供了针对list的操作,包括reverse、fill、copy、swap和addAll方法

Collections.binarySearch(list, key);

集合类的二分查找

3、集合的聚合操作

roster
    .stream()
    .forEach(e -> System.out.println(e.getName());
double average = roster
    .stream()
    .filter(p -> p.getGender() == Person.Sex.MALE)
    .mapToInt(Person::getAge)
    .average()
    .getAsDouble();

待续

猜你喜欢

转载自blog.csdn.net/everlasting_188/article/details/86662499