-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringBuilders.java
More file actions
26 lines (22 loc) · 871 Bytes
/
StringBuilders.java
File metadata and controls
26 lines (22 loc) · 871 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
public class StringBuilders {
public static void main(String[] args) {
//Menos performatico.
long tempoInicial = System.currentTimeMillis();
String alpha = "a";
for (char current = 'b'; current <= 'z';current ++){
alpha += current;
}
System.out.println(alpha);
long tempoFinal = System.currentTimeMillis();
System.out.printf("%.3f ms%n", (tempoFinal - tempoInicial) / 1000d);
//Mais performatico.
long tempoInicial1 = System.currentTimeMillis();
StringBuilder sb = new StringBuilder();
for (char current = 'a'; current <= 'z'; current++){
sb.append(current);
}
System.out.println(sb);
long tempoFinal1 = System.currentTimeMillis();
System.out.printf("%.3f ms%n", (tempoFinal1 - tempoInicial1) / 1000d);
}
}