Section 7.12 Chapter Summary
Subsection 7.12.1 Technical Terms
|data structure||delimited string||delimiter|
|empty string||garbage collection||glyph|
|lexicographic order||logical font||off-by-one error|
|orphan object||physical font||read only|
|string||string index||string literal|
|token||unit indexed||zero indexed|
Subsection 7.12.2 Important Points}
Stringliteral is a sequence of 0 or more characters enclosed within double quotation marks. A
Stringobject is a sequence of 0 or more characters, plus a variety of class and instance methods and variables.
Stringobject is created automatically by Java the first time it encounters a literal string, such as “Socrates,” in a program. Subsequent occurrences of the literal do not cause additional objects to be instantiated. Instead, every occurrence of the literal “Socrates” refers to the initial object.
Stringobject is created whenever the
newoperator is used in conjunction with a
Stringconcatenation operator is the overloaded \(+\) symbol; it is used to combine two
Strings into a single
String: “hello” + “world”
==>“helloworld”. Strings are indexed starting at 0. The
lastIndexOf()methods are used for finding the first or last occurrence of a character or substring within a
valueOf()methods convert a nonstring into a
length()method determines the number of characters in a
charAt()method returns the single character at a particular index position. The various
substring()methods return the substring at particular index positions in a
Strings contain the same exact sequence of characters. The
==operator, when used on
Strings, returns true if two references designate the same
Stringobject. String objects are immutable. They cannot be modified.
StringBufferis a string object that can be modified using methods such as
StringTokenizeris an object that can be used to break a
Stringinto a collection of tokens separated by delimiters. The whitespace characters—tabs, blanks, and newlines—are the default delimiters.
FontMetricsclass is used to obtain the specific dimensions of the the various
Fonts. It is useful when you wish to center text.
Fonts are inherently platform dependent. For maximum portability, it is best to use default fonts.