Java String is a sequence of characters
Example:
"Java"
"1365"
""
" "
"?"
Many ways of constructing a string:
Many ways of constructing a string:
Many ways of constructing a string:
Does Java create 2 String objects internally?
Without “new” operator for String creation:
Java looks into the String pool (Collection of Strings)
Try to find objects with same String value
Advantage of String class:
many built-in methods for String manipulation
String.valueOf(x) – returns String
representation of x.
x: char, int, double, float
Useful for converting different types to String
With frequent modifications of Strings:
Create many new objects – uses up memory
Destroy many unused ones – increase workload
Overall: can slow down performance
All data are in the end binary
(10001110110001) in base 2
In ASCII encoding, one byte
represents one character
Encoding is a rule where you map
characters to integers:
‘a’ = 97 (01100001) in base 2
Resource: http://www.asciichars.com
Chapter 2:
section 2.14
section 2.15
Chapter 7: Objects and Classes