Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
OCA Java SE 8 Programmer I Study Guide 1Z0-808
this week in the
Joined: Sep 04, 2008
Jul 09, 2009 03:21:35
i was going through a blog on
I got the guy using String.format().
I could not get why he was using this.
if i write this
Let private int constant = 1; 1. System.out.println(String.format("%d", constant)); 2. System.out.println(constant));
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?
Joined: Jul 26, 2007
Jul 09, 2009 03:51:22
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!
Joined: Oct 13, 2005
Jul 09, 2009 08:26:07
Also, it produces Strings similar in format to what is described
in the Java™ Tutorials
Smart Bear Support
Joined: Jul 07, 2009
Jul 09, 2009 08:35:56
In the example you gave, yes it is pointless. However String.format(...) is capable of much more complicated and useful stuff.
I agree. Here's the link:
subject: About String.format()
align output with StringBuffer
Display a integer always in two digit
String.format vs java.text.MessageFormat
Doubt in String formatting
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015