Java examples for Language Basics:String
The following statements define and initialize a string variable:
public class Main { public static void main(String[] args) { String s;/*from ww w.j a v a2 s . co m*/ s = "Hello, World!"; System.out.println(s); } }
A string declaration can include an initializer.
public class Main { public static void main(String[] args) { String s = "Hello, World!"; System.out.println(s);// ww w. j a v a 2 s . c om } }
To initialize a local string variable to an empty string, use a statement like this:
public class Main { public static void main(String[] args) { String s = ""; System.out.println("Empty string:"+s); }/*from w w w . jav a 2 s .c o m*/ }