Intro
In this tutorial, we will show how to initialize a String class.
Example
package com.freesamplecode.java.basic;
public class StringInitializationDemo {
public static void main(String[] args){
String str1 = "This is a string object";
String str2 = new String("This is a string object");
char[] chars = {'T','h','i','s',' ','i','s',' ','a',' ', 'S','t','r','i','n','g'};
String str3 = new String(chars);
System.out.println(str1);
System.out.println(str2);
System.out.println(str3);
}
}
Output
This is a string object This is a string object This is a String

0 comments: