Privacy Policy Terms Of Use. Copyright © 2006-2010 Java Tutorials and Examples.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
- /*
- Java String example
- This Java String example describes how Java String object is created and used.
- */
- public class JavaStringExample{
- public static void main(String args[]){
- /*
- String in java represents the character sequence.
- */
- //creates new empty string
- String str1 = new String("");
- //creates new string object whose content would be Hello World
- String str2 = new String("Hello world");
- //creates new string object whose content would be Hello World
- String str3 = "Hello World";
- /*
- IMPORTANT : Difference between above given two approaches is,
- String object created using new operator will always return new String object.
- While the other may return the reference of already created string
- Object with same content, if any.
- */
- System.out.println(str1.length());
- }
- }
- /*
- OUTPUT of the above given Java String Example would be:
- 0
- */

Post new comment