Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

print tab help

 
Ellen fish
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
when I do:
System.out.println("out.txts\t\t"+"asdf");
System.out.println("out.txt\t\t"+"asdf");

I get:
out.txtsasdf
out.txtasdf

Is there a way to align the two print result without adding an extra \t for out.txt?
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out PrintStream's printf method.
 
Ellen fish
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mm..printf doesn't seem to help.
 
Campbell Ritchie
Sheriff
Posts: 48396
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it would, if you used the numbers which set the width of the fields. There are full details in Formatter, and details you can actually understand ( ) in the Java Tutorials.
 
Ellen fish
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hm...another thing I forgot to mention is that I'm using
StringBuffer str = new StringBuffer();
and str.append to connect all the strings together and print out in the end.
I have tried but still couldn't find a way with formater ><
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic