Java Reference
In-Depth Information
A string is a collection of letters (or characters, to be more precise). We can create a string
literal by writing a group of characters inside quote marks like this:
Note: String Constructor Function
You can also create a string object using the following constructor function:
new String("hello")
This will create a new string that is the same as the string literal " hello ",
although it will be classed as an object rather than a primitive value. For this
reason it is preferable to use the string literal notation ... not to mention it re-
quires less typing to use literals!
We can also use single quote marks if we prefer:
If you want to use double quote marks inside a string literal, you need to use single quote
marks to enclose the string. And if you want to use an apostrophe in your string, you need to
employ double quote marks to enclose the string:
"It's me"
Another option is to do what's called escaping the quotation mark. You place a backslash
before the apostrophe so that it appears as an apostrophe inside the string instead of termin-
ating the string:
'It\'s me'
Search WWH ::

Custom Search