-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerformance.java
More file actions
20 lines (16 loc) · 823 Bytes
/
Copy pathPerformance.java
File metadata and controls
20 lines (16 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package String;
public class Performance {
public static void main(String[] args) {
String series = "";
for (int i = 0; i < 26 ; i++) {
char ch = (char)('a' + i);
System.out.print(ch + " ");
series = series + ch; // series += ch
// in the series it is copying the earlier series and appending a value into it and then printing it (every time it is creating a new string bcz strings are immutable) so much of memory/space wastage.
// time complexity of O(n^2)
}
System.out.println(series); // series will be printed only once when the for loop is terminated.
}
}
// Timestamp : 1:14:00
// it would be great if there is a datatype which allow modification in itself. (no new object is needed to create) - StringBuilder