toString align problem

C

Chen Yang

suppose there're three String a[], b[] and c[], the length are not fixed.
how can i make the format a[] b[] c[] so that three arrays align to the
left?

ok, i know it's stupid.. but i don't think using StringTokenizer to
implement my own format is a good idea... plez help me out, thanks a lot!
 
V

VisionSet

Chen Yang said:
suppose there're three String a[], b[] and c[], the length are not fixed.
how can i make the format a[] b[] c[] so that three arrays align to the
left?

ok, i know it's stupid.. but i don't think using StringTokenizer to
implement my own format is a good idea... plez help me out, thanks a lot!

String myArray[] = {"a[]","b[]","c[]"};

String a[] = {"x"};
String b[] = {"x","y"};
String c[] = {"x","y","z"};

What are you going on about?
 
C

Chen Yang

my problem is like this...

String a[] = {"abcdefg", "a b c d e f", "12345"};
String b[] = {"a b c d e f g h i", "abc", "12"};
String c[] = {"ab", "abcdefghij", "1234"};

how can i make each column align to the left when I print them out?

Thanks a lot!


VisionSet said:
Chen Yang said:
suppose there're three String a[], b[] and c[], the length are not fixed.
how can i make the format a[] b[] c[] so that three arrays align to the
left?

ok, i know it's stupid.. but i don't think using StringTokenizer to
implement my own format is a good idea... plez help me out, thanks a lot!

String myArray[] = {"a[]","b[]","c[]"};

String a[] = {"x"};
String b[] = {"x","y"};
String c[] = {"x","y","z"};

What are you going on about?
 
T

Tony Dahlman

Chen said:
my problem is like this...

String a[] = {"abcdefg", "a b c d e f", "12345"};
String b[] = {"a b c d e f g h i", "abc", "12"};
String c[] = {"ab", "abcdefghij", "1234"};

how can i make each column align to the left when I print them out?

Thanks a lot!
What happens by default? Right alignment? If so, how did you
do that? In other words, what code are you having trouble with?
 
G

Glen Herrmannsfeldt

Chen Yang said:
suppose there're three String a[], b[] and c[], the length are not fixed.
how can i make the format a[] b[] c[] so that three arrays align to the
left?

ok, i know it's stupid.. but i don't think using StringTokenizer to
implement my own format is a good idea... plez help me out, thanks a lot!

So there are three string arrays, and you want to print in columns?

Loop through each to find the longest one, then print each followed by
enough space to make them align.

I think there is a method in String that will repeat a character some number
of times.

-- glen
 
V

VisionSet

Chen Yang said:
my problem is like this...

String a[] = {"abcdefg", "a b c d e f", "12345"};
String b[] = {"a b c d e f g h i", "abc", "12"};
String c[] = {"ab", "abcdefghij", "1234"};

how can i make each column align to the left when I print them out?

Thanks a lot!

Loop through your array with this in a System.out.print

a+"\t";

\t being the tab character

this will align everything to a certain extent so long as there isn't too
much difference between string lengths. Otherwise it will have to be adding
padding as mentioned in another post
 
N

nos

be sure to use a font that has equal width characters

Glen Herrmannsfeldt said:
Chen Yang said:
suppose there're three String a[], b[] and c[], the length are not fixed.
how can i make the format a[] b[] c[] so that three arrays align to the
left?

ok, i know it's stupid.. but i don't think using StringTokenizer to
implement my own format is a good idea... plez help me out, thanks a
lot!

So there are three string arrays, and you want to print in columns?

Loop through each to find the longest one, then print each followed by
enough space to make them align.

I think there is a method in String that will repeat a character some number
of times.

-- glen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top