-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStringUpdate.java
More file actions
33 lines (30 loc) · 897 Bytes
/
StringUpdate.java
File metadata and controls
33 lines (30 loc) · 897 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
package JavaCoreTechMooc.fin;
/**
* Created by Edwin Xu on 5/8/2020 10:23 PM
*/
public class StringUpdate {
public static void main(String[] args) {
final int N = 100000;
long b = System.currentTimeMillis();
String res ="";
for (int i = 0; i < N; i++) {
res+=i;
}
long e = System.currentTimeMillis();
System.out.println(e-b); //4431
b = System.currentTimeMillis();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < N; i++) {
sb.append(i);
}
e = System.currentTimeMillis();
System.out.println(e-b); //62
b = System.currentTimeMillis();
StringBuilder sbl = new StringBuilder();
for (int i = 0; i <N ; i++) {
sbl.append(i);
}
e = System.currentTimeMillis();
System.out.println(e-b); //3
}
}