docs: update docs/java.md. (#601)
This commit is contained in:
parent
2b6b58d7fb
commit
1b9437656d
34
docs/java.md
34
docs/java.md
@ -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);
|
||||
|
||||
|
||||
```
|
||||
|
||||
另见
|
||||
---
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user