-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathApplication.java
More file actions
53 lines (44 loc) Β· 1.86 KB
/
Copy pathApplication.java
File metadata and controls
53 lines (44 loc) Β· 1.86 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
50
51
52
53
package Chapter2.Day6;
public class Application {
public static void main(String[] args) {
// String μ λΆλ³κ°μ²΄μ§λ§, new λ‘ μμ±νλ©΄ λ§€λ² μλ‘μ΄ κ°μ²΄κ° λμ¨λ€.
// λ°λΌμ λΆνμν κ°μ²΄κ° μμ±λλ€.
String str = new String("hello");
String str2 = new String("hello");
// false
System.out.println(str == str2);
/**
* public static Integer valueOf(int i) {
* if (i >= IntegerCache.low && i <= IntegerCache.high)
* return IntegerCache.cache[i + (-IntegerCache.low)];
* return new Integer(i);
* }
*
* Integer μ valueOf() λ IntegerCache() λ₯Ό μ¬μ©νλ€.
* Integer integer = 1; μ νλ©΄ μλμΌλ‘ valueOf λ‘ κ°μ Έμ¨λ€.
*
* IntegerCache() μ ꡬνλΆλ₯Ό 보면 -128 ~ 127 μ μ«μλ μΊμνμ¬ μ¬μ©νλ€.
*/
Integer one = 1;
Integer one2 = 1;
System.out.println(one == one2);
long beforeTime = System.currentTimeMillis();
System.out.println(beforeTime);
Integer[] intArr = new Integer[30000000];
// Caching
for (int i = 0; i < 20000000; i++) {
intArr[i] = 1;
}
System.out.println("μΊμ± μμμκ°(1) : " + (System.currentTimeMillis() - beforeTime));
beforeTime = System.currentTimeMillis();
for (int i = 0; i < 20000000; i++) {
intArr[i] = 127;
}
System.out.println("μΊμ± μμμκ°(127) : " + (System.currentTimeMillis() - beforeTime));
beforeTime = System.currentTimeMillis();
for (int i = 0; i < 20000000; i++) {
intArr[i] = 128;
}
System.out.println("μΊμ±μν μμμκ°(128) : " + (System.currentTimeMillis() - beforeTime));
}
}