hi,
in java, how do we format fields. for instance, suppose i want a double to print upto 3 decimal #'s, how do we specify this.
i want to do this for other data types as well, int, etc...
Alternatively, if you have access to Tiger then you can start using more advanced formatting functionality with the inbuilt Formatter class :
The Formatter class also has the ability to make it much easier to read formatted input.
Usage
Formatter myFormatter=new Formatter()
foratter.format("This %s is %d characters","String",6);
Prints
This String is 6 characters
So if you know C and have used its printf(...) methods, you should find the Formatter class quite easy to use.
One excellent feature of the Formatter class is that it allows you to specify argument indexes. This has the added benefit where you do not need to specify an argument twice to have 2 or more formatting options applied to it :-
formatter.format("%s in uppercase is %1$S",hello);
I've heard that 1.5 is quicker than 1.4, but frankly didn't believe it could be, unless they have rewritten the JIT compiler/interpreter, which I thought they had not - is it really quicker in your opinion ?
Well, I've just read about it, not tested, but they improved the performace changing garbage collection, class sharing, thread priorities and some new no synchornized classes.
I guess that it can be faster if you rewrite your code to take full advantage of the new features. That's why I'ma asking, does it worth the work?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.