This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes About String.format() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "About String.format()" Watch "About String.format()" New topic

About String.format()

kayanaat sidiqui
Ranch Hand

Joined: Sep 04, 2008
Posts: 122
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?

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268

Check out the API docs for the Formatter class to get a better understanding of the method.

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38467
Also, it produces Strings similar in format to what is described here in the Java™ Tutorials
Roy Paterson
Smart Bear Support

Joined: Jul 07, 2009
Posts: 6
In the example you gave, yes it is pointless. However String.format(...) is capable of much more complicated and useful stuff.

Smart Bear
It is sorta covered in the JavaRanch Style Guide.
subject: About String.format()