• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What's in new String() object?

 
Charles Chikito
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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
Posts: 15205
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's an empty string - a string with zero characters, so it prints nothing. Just like:
 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Charles Chikito
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Yes you are right. The above program also prints the same thing. Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic