Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Java does not include a sprintf equivalent

Name: Anonymous 2010-02-08 12:36

in it's bloated standard library. I just found that out and I am shocked and disappointed.

Name: Anonymous 2010-02-08 12:38

Read SIJP

Name: Anonymous 2010-02-08 12:39

http://java.sun.com/j2se/1.4.2/docs/api/java/text/Format.html
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html
I don't even know Java, and I could look this up. Don't expect things to be named the same in all languages you program in.

Name: Anonymous 2010-02-08 12:45

OP is dumber than Java.

Java also comes with standard object types that hold double and floats that maintain specific precision.

Name: Anonymous 2010-02-08 13:48

The operation's noun you're looking for it's `string interpolation`. Now http://lmgtfy.com/?q=java+string+interpolation

Name: Anonymous 2010-02-08 15:08

>>3
That just prints objects as strings. OP wants format string functionality.

Name: Anonymous 2010-02-08 16:00

>>6
You're looking at a class very close to the root of all Java - Object - so you should not expect too much in the way of specifics.  Look at some of the classes extending from Format, especially MessageFormat.

http://java.sun.com/j2se/1.4.2/docs/api/java/text/MessageFormat.html

Name: Anonymous 2010-02-09 0:03

>>1
Dude, String has a static format() method. If that isn't sprintf then I don't know what is.

Name: Anonymous 2010-02-10 15:29

>>8
It cannot pad number with spaces.

Name: Anonymous 2010-02-10 16:29

>>9

$ cat Test.java
public class Test {
  public static void main(String... args) throws Exception {
    System.out.println(String.format("x%20dy\nx%-20dy", 1, 2));
  }
}

$ javac Test.java && java Test
x                   1y
x2                   y

Name: !iN.MY.aRMs 2010-02-10 16:45

world best buisnes framework+language is:
http://1c.ru/eng/title.htm
over 12x faster development than java
use it and save u money

Name: GRUNNUR 2010-02-11 6:18

>>11
"GRUNNUR"

Name: ​​​​​​​​​​ 2010-10-23 22:36

Name: ​​​​​​​​​​ 2010-10-25 11:10

Name: Anonymous 2010-12-08 21:55

Name: Anonymous 2011-02-04 19:17


Don't change these.
Name: Email:
Entire Thread Thread List