2016-06-28
1 String variables
String class
"Hello world!"
"This is a string"
PackageDay10; Public classteststring { Public Static voidMain (string[] args) {//String mystring;//mystring= "Hello world!";//System.out.println (mystring);String name= "Tom"; String Sex= "Male"; String from= "China"; String Info= "The name is:" +name+ "\ n sex is:" +sex+ "\ n from:" +From ; SYSTEM.OUT.PRINTLN (info); }}
2 String Connection
You can use + to connect two strings, + here is a join operator
Escape characters:
Each escape character consists of two symbols, but the compiler treats him as a character
\ n A newline character is another line, and the cursor moves to the beginning of the next line
\ t tab
\ r Carriage return moves the cursor to the beginning of the bank
Package Day10; Public class Testtrans { publicstaticvoid main (string[] args) { // declares a string that contains an escape character string teststr= "double quotation mark \" single quotation mark \ ' backslash \ \ Next line \ n tab \ t return character \ r "; System.out.println (TESTSTR); System.out.println (Teststr.length ());} }
Resources
[1] Java Easy Start Classic tutorial "full version"
Java section 10th First knowledge string