class StringExample { public static void main(String args[]) { // creating a String literal String str1 = "This is the first string."; // create a new String Object String str2 = new String("This is the 2nd string."); System.out.println("str1: " + str1 ); System.out.println("str2: " + str2 ); } }
$ java StringExample str1: This is the first string. str2: This is the 2nd string.
String: .../api/java/lang/String.html
How to Declare and Initialize a String in Java? How do you initialize a String in java?
Basis Java Class
Command Line Arguments
Commenting
Hello World Example
Java Escape Sequences
Random Numbers
Scanner and String Tokenizer Example
String Example