Analysis of the aggregation operation of Java 8

Source: Internet
Author: User
Tags modifier new features

Oracle posted Java 8 as scheduled on March 19, 2014. The Java 8 version is considered a landmark release in which Oracle has added many new features, including lambda expressions, method references, enhanced security, and more.

Of the many new features, the aggregation operation (Aggregate Operations) is a relatively large change to the collection class. With aggregation, it is easier for developers to use lambda expressions and easier to find, traverse, filter, and compute the collection.

Aggregation operations are related to new features such as lambda expressions and method references in Java 8, and are generally used together, but this only illustrates the use of aggregation operations, and the following is a brief description of the use of aggregation operations.

Hierarchical structure of collection classes

Collection class is a kind of auxiliary class provided by Java language, and it is a general data structure, such as map, Set, list, etc. The collection class hierarchy in Java is as follows:

Figure 1

As shown above, collection is the main collection class interface, its sub-interface (interface) has deque, Queue, Set, list and so on.

A map is a collection of another type that stores data sets with key values of keys and value.

In Java 8, the following methods were added to the Java.util.Collection interface:

Stream<e> Stream () {return
    Streamsupport.stream (Spliterator (), false);

The visibility modifier for the stream () method is default, which is a new feature of Java 8. In an interface (collection is interface), the method implementation is not needed (and cannot), but it is different when the default modifier is introduced. Developers can not only implement methods, but also do not need to consider the issue of backward compatibility. For a detailed explanation of default method, the reader can refer to the official documentation for Java 8.

It is the stream method that leads to aggregation operations of the collection class.

[ note]

There is no stream () method in the map interface, but the values () and keyset () of the map return the collection object, and of course the stream () method can be used on the collection object.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.