This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

About String.format()  RSS feed

 
kayanaat sidiqui
Ranch Hand
Posts: 122
  • 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
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 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
Posts: 53750
127
  • 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
  • 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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!