printf() analogue in java 1.4? I need to set text width and justification

I need to print table to console. Before output text to cell I need to set text width and justification. How to do it in java 1.4.In 1.5 I'd use printf().
[176 byte] By [x4444a] at [2007-11-27 6:54:41]
# 1
I would probably look for a free library that does the same. Your second option (what I usually used to do) is to write a small utility method that uses a StringBuffer to pad information.Kaj
kajbja at 2007-7-12 18:29:46 > top of Java-index,Java Essentials,Java Programming...
# 2

> I need to print table to console.

> Before output text to cell I need to set text width

> and justification. How to do it in java 1.4.

>

> In 1.5 I'd use printf().

There's no such functionality in 1.4. You'll have to roll your own.

public class Main {

static String myPrintf(String str, int width, char fill) {

StringBuffer b = new StringBuffer();

while((width--)-str.length() > 0) {

b.append(fill);

}

b.append(str);

return b.toString();

}

public static void main(String[] args) {

System.out.println("["+myPrintf("abc", 10, ' ')+"]");

}

}

prometheuzza at 2007-7-12 18:29:46 > top of Java-index,Java Essentials,Java Programming...
# 3
> There's no such functionality in 1.4. You'll have to> roll your own.> ...Yeah, or like Kaj suggested: find a 3rd party lib that does this (including lot's of other cool things of course!).; )
prometheuzza at 2007-7-12 18:29:46 > top of Java-index,Java Essentials,Java Programming...