-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.java
More file actions
60 lines (34 loc) · 1.28 KB
/
string.java
File metadata and controls
60 lines (34 loc) · 1.28 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
Strings are immutable in Java
when you are appending strings
watch out for the cost of operations
String is backed by a char array
*/
[java]
{
String name = "Value";
name.toLowerCase();
name.toUpperCase();//very self explanatory
name.substring(beginning , end-non inclusive)
name.charAt(index);
name.replace(String toBeErased, String rePlacement);
}[java]
// You can just add/append to the string same way you add/append to literals
//Using String builder because string is immutable
-----------------------------------------------------------
String Builder Usage
-----------------------------------------------------------
- Not the best for concurrency problems
- No gurantee of synchronization - not safe for multi-threading
[java]{
StringBuilder name = new StringBuilder(int capcity);
StringBuilder name = new StringBuilder(String str);
name.append();//append given argument to the end of the invoked object
name.insert(Integer index, String toBeInserted);
//insert behind given position
name.replace(Integer index, String rePlacement);
name.reverse();//revese the given string
name.delete();//deletes from the specific end/beginning index
}
//the cost of operation for trimming a string
//what the fuck is regex and how do you split string?