-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
44 lines (33 loc) · 1.44 KB
/
Copy pathMain.java
File metadata and controls
44 lines (33 loc) · 1.44 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
public class Main {
public static void main(String[] args) {
String helloWorld = "Hello" + " World";
helloWorld.concat(" and Goodbye");
StringBuilder helloWorldBuilder = new StringBuilder("Hello" + " World");
helloWorldBuilder.append(" and Goodbye");
printInformation(helloWorld);
printInformation(helloWorldBuilder);
StringBuilder emptyStart = new StringBuilder();
emptyStart.append("a".repeat(57));
StringBuilder emptyStart32 = new StringBuilder(32);
emptyStart32.append("a".repeat(17));
printInformation(emptyStart);
printInformation(emptyStart32);
StringBuilder builderPlus = new StringBuilder("Hello" + " World");
builderPlus.append(" and Goodbye");
builderPlus.deleteCharAt(16).insert(16, 'g');
System.out.println(builderPlus);
builderPlus.replace(16,17,"G");
System.out.println(builderPlus);
builderPlus.reverse().setLength(7);
System.out.println(builderPlus);
}
public static void printInformation(String string) {
System.out.println("String = " + string);
System.out.println("Length = " + string.length());
}
public static void printInformation(StringBuilder builder) {
System.out.println("StringBuilder = " + builder);
System.out.println("Length = " + builder.length());
System.out.println("Capacity = " + builder.capacity());
}
}