Java programming String and String methods, length, charAt, subString

preview_player
Показать описание
Strings and String Methods
The String Class

A string is a sequence of characters
Strings are objects of the String class
A string literal is a sequence of characters enclosed in double quotation marks:
"Hello, World!"

String length

String length is the number of characters in the String
Example: String fName = "Shin";
Empty string: ""
String Concatenation - use + sign to concatenate strings to one long string

Example

String fName = "Shin";

String lName ="Liu";

String FullName = fName + " " + lName;

the output of FullName will be: Shin Liu



Read String Input - Use String's next method to read string

Example:

When a string is read with the next method, only one word is read. For example, suppose the user types



Escape Sequences: Use escape sequence \" to indicate the quotations mark that follows should be a part of the string and not mark the end of the string.

For Example:

To include an quotation sign around text "Java" in the output

Professor Liu says "Java" is the best programming language.

The code should be

* use the escape sequence of \\ to include a backslash in a string *

for example: to locate java project directory in your PC

C:\Users\SHIN\eclipse-workspace

The code to create this directory path should be



String method charAt return a char value from a string, The first string position is label 0, the second is 1...

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
R i o H o n d o C o l l e g e
For example:

String collegeName = "Rio Hondo College"

Substrings

For example:

String collegeName = "Rio Hondo College";

If you omit the end position when calling the substring method, then all characters from the starting position to the end of the string are copied.
Рекомендации по теме
visit shbcf.ru