Explanation
1. Sorted is also an intermediate operation, and the parameter returned is a Stream. Likewise, we can pass in a Comparator that defines the ordering, and if none is passed, the default ordering is used.
2. sorted will not make any changes to stringCollection. stringCollection is the original elements, the order is unchanged.
Example
stringCollection .stream() .sorted() .filter((s) -> s.startsWith("a")) .forEach(System.out::println); // "aaa1", "aaa2" System.out.println(stringCollection); // ddd2, aaa2, bbb1, aaa1, bbb3, ccc, bbb2, ddd1
The basic data types of Java are divided into:
1. Integer type , a data type used to represent integers.
2. Floating point type, a data type used to represent decimals.
3. Character type. The keyword of character type is "char".
4. Boolean type is the basic data type that represents logical values.
The above is the detailed content of Sorted sorting method in java. For more information, please follow other related articles on the PHP Chinese website!