Part 3 typestring - Type String Type String Type String is...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Type String Type String Type String is different from primitive types int and double . String is a class type. We explain what this means later, after we have explained what a class is. Each value of type String is a sequence of characters. We write a value by enclosing the sequence of char- acters within double quotes " . You can see in the interactions pane of DrJava that these literals evaluate to themselves. The second example contains a capital letter and three occurrences of the space, or blank character, which is a character. The last example shows the empty string , the string containing no characters. "first"    " The  price is $25.00."    "5 <= 20"    "" Use a new-line character "\n" to indicate a jump to a new line. For example, notice how evaluation of "123\n4" appears on two lines. The new-line character begins with the so-called escape character, the back- slash. Use the escape character to write the backslash itself, as well as the double quote character. For example, note how the String literal "1\\2\"3" evaluates to a String containing can contain the characters 1. \, 2, " , and 3. Look in the text, Chapter 6, to find other characters that are written using the escape character.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

Part 3 typestring - Type String Type String Type String is...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online