This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

print tab help  RSS feed

 
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
Posts: 20904
81
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: 53779
128
  • 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 ><
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!