• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About String.format()

 
kayanaat sidiqui
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

i was going through a blog on java.
I got the guy using String.format().

I could not get why he was using this.

if i write this


Both will give same result i.e. 1.

Is java people included this because of giving feel of c/c++?

Is there any important role of this method?

Thanks,
Kaya.
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the API docs for the Formatter class to get a better understanding of the method.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47231
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, it produces Strings similar in format to what is described here in the Java™ Tutorials
 
Roy Paterson
Smart Bear Support
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the example you gave, yes it is pointless. However String.format(...) is capable of much more complicated and useful stuff.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic