-
Notifications
You must be signed in to change notification settings - Fork 0
/
#2_string_notes.txt
38 lines (28 loc) · 2.04 KB
/
#2_string_notes.txt
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
string: inspection, comparison, manipulation
inspection: length, charAt, indexOf, lastIndexOf, isEmpty, isBlank
<...>.charAt(index): use for string, returns character
<...>[index]: use for array, returns character
<...>.indexOf(<char>): returns integer index
comparison: contentEquals, equals, equalsIgnoreCase, contains, startsWith, endsWith, regionMatches
contentEquals, equals: returns boolean if string value = value of arguments passed; latter is only for strings
contains: returns boolean if string contains argument passed
regionMatches: returns boolean if sub-regions are matched
manipulation: type 1 ~ clean-up: indent, strip, stripLeading, stripTrailing, trim, toLowerCase, toUpperCase
strip: removes all leading and trailing white spaces
trim: removes only one leading and one trailing white space, not all
type 2 ~ transformation: concat, join, repeat, replace, replaceAll, replaceFirst, substring, subSequence
concat: string + text = string
join: concats many elements with delimiter
// ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
character to string: String.valueOf(<char>)
// ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
String: defined as a variable;
uses concat;
when manipulated, should be assigned to a variable;
creates new object, returns new reference;
StringBuilder class: defined as an object;
uses append;
when manipulated, does not need to be assigned to a variable
(value of object changed, behaves like a queue);
returns self-reference;
delete, deleteCharAt, insert, reverse, setLength