-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMethodReference.java
More file actions
49 lines (33 loc) · 1.1 KB
/
MethodReference.java
File metadata and controls
49 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package lambda;
import java.util.*;
/**
* Created by Edwin Xu on 5/3/2020 4:26 PM
*/
public class MethodReference {
public static void main(String[] args) {
String s[] = {"sd","fgfgfg"};
Arrays.sort(s,String::compareToIgnoreCase);
for (String i:s) System.out.println(i);
ArrayList<Integer> a = new ArrayList<>();
a.add(1);
a.add(12);
a.forEach(System.out::println);
int arr[] = {1,1,1,1,23,2,32332,234,3,434,342,32,32,323,4,44,4};
Map<Integer,Integer> map = new HashMap<>();
for (int i : arr) {
map.merge(i,1,Integer::sum);
}
for (Map.Entry<Integer,Integer> e : map.entrySet()) {
System.out.println(e.getKey()+":"+e.getValue());
}
int [] arr1 = {1,2,2,3,3,3};
Map<Integer,Integer> m = new HashMap<>();
for (int i : arr1) {
m.merge(i,1,(aa,b)->(aa+b));
// m.merge(i,1,Integer::sum);
}
for (Map.Entry<Integer,Integer> e : m.entrySet()) {
System.out.println(e.getKey()+":"+e.getValue());
}
}
}