You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
int i = s1.compareTo(s2); // 32; lowercase follows uppercase
22
+
if (i <0) {
23
+
// s1 precedes s2
24
+
} elseif (i >0) {
25
+
// s1 follows s2
26
+
} else {
27
+
// s1 equals s2
28
+
}
29
+
30
+
// Check order of two strings ignoring case
31
+
i = s1.compareToIgnoreCase(s3); // -1
32
+
if (i <0) {
33
+
// s1 precedes s3
34
+
} elseif (i >0) {
35
+
// s1 follows s3
36
+
} else {
37
+
// s1 equals s3
38
+
}
39
+
40
+
// A string can also be compared with a StringBuffer;
41
+
// see Constructing a String
42
+
StringBuffer sbuf =newStringBuffer("a");
43
+
b = s1.contentEquals(sbuf); // true
44
+
```
45
+
46
+
## Constructing a String
47
+
48
+
If you are constructing a string with several appends, it may be more efficient to construct it using a `StringBuffer` (synchronized), `StringBuilder` (non-synchronized) and then convert it to an immutable `String` object.
0 commit comments