This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread 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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 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: 10747

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: 44585
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
I agree. Here's the link:
subject: About String.format()
It's not a secret anymore!