String Methods:
String txt = "Hello World"; System.out.println(txt.toUpperCase()); // Outputs "HELLO WORLD" System.out.println(txt.toLowerCase()); // Outputs "hello world"
String txt = "Please locate where 'locate' occurs!"; System.out.println(txt.indexOf("locate")); // Outputs 7 System.out.println(txt.indexOf("p")); // Outputs 0 System.out.println(txt.indexOf("l")); // Outputs 1
String firstName = "John "; String lastName = "Doe"; System.out.println(firstName.concat(lastName));
String x = "10"; String y = "20"; String z = x + y; // z will be 1020 (a String)
String x = "10"; int y = 20; String z = x + y; // z will be 1020 (a String)
Special Characters
Escape character | Result | Description |
---|---|---|
' | ' | Single quote |
" | " | Double quote |
\ | Backslash |
Code | Result | |
---|---|---|
n | New Line |
String txt = "HellonWorld!"; // Outputs Hello |
r | Carriage Return |
String txt = "HellorWorld!"; // Outputs Hello |
t | Tab |
String txt = "HellotWorld!"; // Outputs Hello World! |
b | Backspace |
String txt = "Helblo World!"; // Outputs Helo World! |