docs: update docs/java.md. (#601)

This commit is contained in:
YuRuiH 2024-04-09 11:44:38 +08:00 committed by GitHub
parent 2b6b58d7fb
commit 1b9437656d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1038,6 +1038,40 @@ Map<Integer, Long> frequencyMap = list.stream().collect(Collectors.groupingBy(x
// 3: 1
```
`Stream``JAVA 8`添加的新特性,类似于一种管道。
```java
// Create the stream
List<String> test = Arrays.asList("123", "456", "789");
Stream<String> stram = test.stream();
// some intermediate operations
// fillter
// The original operation
List<TestDO> resultList = new ArrayList<>();
for(TestDO test: testList){
if(test.getTest().equals(Boolean.TRUE){
resultList.add(test);
}
}
// The stream operation
List<TestDO> resultList = testList.stream().fillter(test -> test.getTest().equals(Boolean.TRUE)).collect(Collectors.toList());
//distinct
List<String> test = Arrays.asList("123", "456", "789", "123");
test.stream().distinct().forEach(System.out::println);
//map
List<String> test = Arrays.asList("123", "456", "789", "123");
test.stream().map(i -> i + "hh").forEach(System.out::println);
// sorted
List<Integer> numbers = Arrays.asList(3, 2, 1);
numbers.stream().sorted().forEach(System.out::println);
```
另见
---