forked from AndrewProgramming/JavaTutorialCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoBoxingAndUnBoxing.java
More file actions
40 lines (30 loc) · 940 Bytes
/
AutoBoxingAndUnBoxing.java
File metadata and controls
40 lines (30 loc) · 940 Bytes
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
package basic;
import java.util.ArrayList;
import java.util.List;
public class AutoBoxingAndUnBoxing {
public static void main(String[] args) {
List<Integer> list = new ArrayList<>();
list.add(1);
list.add(Integer.valueOf(1));
AutoBoxingAndUnBoxing autoBoxingAndUnBoxing = new AutoBoxingAndUnBoxing();
Integer num = new Integer(10);
autoBoxingAndUnBoxing.unboxingDemo(10);
Integer sum = 0;
long start = System.currentTimeMillis();
for (int i = 0; i < 1_000_000_000; i++) {
sum = sum + i;
}
long end = System.currentTimeMillis();
System.out.println(end - start);
int sum1 = 0;
long start1 = System.currentTimeMillis();
for (int i = 0; i < 1_000_000_000; i++) {
sum1 = sum1 + i;
}
long end1 = System.currentTimeMillis();
System.out.println(end1 - start1);
}
public void unboxingDemo(Integer num) {
System.out.println("num:" + num);
}
}