How Java String object is created and used. - Java Language Basics

Java examples for Language Basics:String

Description

How Java String object is created and used.

Demo Code


public class Main {
 
  public static void main(String args[]){
 
      /* creates new empty string */
      String str1 = new String("");
     /* w  ww  . ja  va  2s  . c  o  m*/
      String str2 = new String("Hello world");
     
      String str3 = "Hello Wolrd";
     
      System.out.println( str1.length());
  }
 
}

Result


Related Tutorials