This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes What's in new String() object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What Watch "What New topic
Author

What's in new String() object?

Charles Chikito
Ranch Hand

Joined: May 22, 2009
Posts: 76



This program prints nothing. The String s = new String(); creates a new object of class String. What does it contains if not null?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

It's an empty string - a string with zero characters, so it prints nothing. Just like:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1752
    
    7

java.lang.String

API documentation wrote:
public String()
Initializes a newly created String object so that it represents an empty character sequence. Note that use of this constructor is unnecessary since Strings are immutable.


Edit: Grrr, stop that


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Charles Chikito
Ranch Hand

Joined: May 22, 2009
Posts: 76


Yes you are right. The above program also prints the same thing. Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What's in new String() object?
 
Similar Threads
String explain output
is this object eligible for garbage collection??
GC doubt
Doubt about ClassCastException (was: Doubt)
javabeat generics question doubt