5. Kotlin's collection framework

1. What is the difference compared with Java?
The interface of the "immutable" collection framework has been added. Did not start over, reuse all implementation types of Java API.
Provides rich and easy-to-use methods, such as forEach/map/flatMap. Scala is also a JVM language, and many features of Kotlin refer to Scala. Operator-level support simplifies access to the collection framework.
Insert picture description here
Second, Kotlin's collection usage
has its own type, so it is a "first-class citizen", which can be assigned, passed, and called under appropriate conditions.
The following is the usage of various functions, the key points are written in the comments:
Insert picture description here

3. Pair means right. It means a key-value pair. It contains two elements, and Triple contains three elements.
Insert picture description hereInsert picture description here
4. Function analysis
1. Unit is equivalent to Java's void function and the return value is Unit, which can be omitted.
Insert picture description here
Insert picture description here

2. Function reference Insert picture description here
Insert picture description here
Simplified reference
Insert picture description here
Insert picture description here
method The difference between function and method, method can be regarded as a special type of function. Formally, a function with a receiver can be called a method. The receiver is an instance of the class. The functions in this class instance are called methods, such as cityBean.getCity(), cityBean is the receiver, and getCity() is called the method.
Insert picture description here
Insert picture description here
Insert picture description here
The above figure shows two different ways of calling formal parameter methods.

3. Variable length parameters and multiple return values
Insert picture description here
Insert picture description here

Author: Cangshuipu witch cloud
blog: http: //blog.csdn.NET/amir_zt/
more original, please indicate the source, thank you.
https://blog.csdn.net/amir_zt/article/details/113172706

Guess you like

Origin blog.csdn.net/u011635351/article/details/113172706