Java Strings: Creating Strings String Methods
Java Strings: Creating Strings String Methods
Creating Strings
String Methods
Java Strings
Storing Text in String Variables
Using Special Characters in String
Display Strings
Concatenate Strings
Using Other Variables with Strings
Strings are sequences of characters beginning
and ending with double-quotes.
char message;
When you create character variables, you can set them up
with an initial value.
Using the String literal and the name of the variable, you can
set up a variable to hold a string value.
System.out.println(“Hello World!”);
String a = “Hello”;
String b = “World”;
String message = a + b;
Output:
“Computer”
str2
str3
“Computer”
“Computer”
str4
Assume: String str = “Java”;
Method Example Return value
charAt(index) str.charAt(2) ‘v’
compareTo(string) str.compareTo(“Java’s”) -2
concat(string) str.concat(“ program”) “Java program”