ch16 - A program may contain character literals. An integer...

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

View Full Document Right Arrow Icon
Background image of page 1

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

View Full DocumentRight Arrow Icon
A program may contain character literals . An integer value represented as a character in single quotes. The value of a character literal is the integer value of the character in the Unicode character set . String literals (stored in memory as String objects) are written as a sequence of characters in double quotation marks. Class String is used to represent strings in Java. The next several subsections cover many of class String ’s capabilities.
Background image of page 2
N o-argument constructor creates a String that contains no characters (i.e., the empty string , which can also be represented as "" ) and has a length of 0. C onstructor that takes a String object copies the argument into the new String . C onstructor that takes a char array creates a String containing a copy of the characters in the array. C onstructor that takes a char array and two integers creates a String containing the specified portion of the array.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
String method length determines the number of characters in a string. String method charAt returns the character at a specific position in the String . String method getChars copies the characters of a String into a character array. The first argument is the starting index in the String from which characters are to be copied. The second argument is the index that is one past the last character to be copied from the String . The third argument is the character array into which the characters are to be copied. The last argument is the starting index where the copied characters are placed in the target character array.
Background image of page 8
Background image of page 9

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

View Full DocumentRight Arrow Icon
Background image of page 10
Strings are compared using the numeric codes of the characters in the strings. Figure 16.3 demonstrates String methods equals , equalsIgnoreCase , compareTo and regionMatches and using the equality operator == to compare String objects.
Background image of page 11

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

View Full DocumentRight Arrow Icon
Background image of page 12
Background image of page 13

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

View Full DocumentRight Arrow Icon
Background image of page 14
Background image of page 15

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

View Full DocumentRight Arrow Icon
Method equals tests any two objects for equality The method returns true if the contents of the objects are equal, and false otherwise. Uses a lexicographical comparison . When primitive-type values are compared with == , the result is true if both values are identical. When references are compared with
Background image of page 16
Image of page 17
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 57

ch16 - A program may contain character literals. An integer...

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

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