472,146 Members | 1,316 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

char to string ????

Is there a method or way for me to take a couple of char's and make a sting
out of them .

Example of what I want to do.

String | char
b = b
ba = a
bad = d
Jul 17 '05 #1
8 19960
"Jova" <Na**@dotcom.com> wrote in message news:<FR*********************@news4.srv.hcvlny.cv. net>...
Is there a method or way for me to take a couple of char's and make a sting
out of them .

Example of what I want to do.

String | char
b = b
ba = a
bad = d

couple of char ... char[] couple = {'m', 'f'};
make a string ... String s = new String(couple); // "mf"

Is this what you want?
Jul 17 '05 #2
Yes. Thank You
"hiwa" <HG******@nifty.ne.jp> wrote in message
news:68**************************@posting.google.c om...
"Jova" <Na**@dotcom.com> wrote in message

news:<FR*********************@news4.srv.hcvlny.cv. net>...
Is there a method or way for me to take a couple of char's and make a sting out of them .

Example of what I want to do.

String | char
b = b
ba = a
bad = d

couple of char ... char[] couple = {'m', 'f'};
make a string ... String s = new String(couple); // "mf"

Is this what you want?

Jul 17 '05 #3
HG******@nifty.ne.jp (hiwa) wrote in message news:<68**************************@posting.google. com>...
"Jova" <Na**@dotcom.com> wrote in message news:<FR*********************@news4.srv.hcvlny.cv. net>...
Is there a method or way for me to take a couple of char's and make a sting
out of them .

Example of what I want to do.

String | char
b = b
ba = a
bad = d

couple of char ... char[] couple = {'m', 'f'};
make a string ... String s = new String(couple); // "mf"

Is this what you want?


Another approach would be, where 'b', 'a' and 'd' are chars:

String s = b + a + d + "";

Generally any concatenation involving a string results in a String.
So if you need to a sum, at the same time, you need to isolate it
in brackets:

String s = b + (1+3) + d + "";

Of course if you already have an array of chars, then Jova's
approach is best.

regards

Andre
Jul 17 '05 #4

"Tarken" <ta****@lycos.co.uk> wrote in message
news:e9**************************@posting.google.c om...
HG******@nifty.ne.jp (hiwa) wrote in message

news:<68**************************@posting.google. com>...
"Jova" <Na**@dotcom.com> wrote in message news:<FR*********************@news4.srv.hcvlny.cv. net>...
Is there a method or way for me to take a couple of char's and make a sting out of them .

Example of what I want to do.

String | char
b = b
ba = a
bad = d

couple of char ... char[] couple = {'m', 'f'};
make a string ... String s = new String(couple); // "mf"

Is this what you want?


Another approach would be, where 'b', 'a' and 'd' are chars:

String s = b + a + d + "";

Generally any concatenation involving a string results in a String.
So if you need to a sum, at the same time, you need to isolate it
in brackets:

String s = b + (1+3) + d + "";


I thought it would evaluate left to right, so String s = b + a + d + "";
would be equivalent to

String s = ((( b + a ) + d ) + ""; which is not what was asked for. If you
put the "" first it should work, though. If b, a, and d are int's that is
what it would do. It might treat char specially.

You can also create a StringBuffer, add the chars one at a time, and then
make a String from it.

-- glen

Jul 17 '05 #5
my book says left to right also

"Glen Herrmannsfeldt" <ga*@ugcs.caltech.edu> wrote in message
news:I6onb.47477$HS4.225638@attbi_s01...

"Tarken" <ta****@lycos.co.uk> wrote in message
news:e9**************************@posting.google.c om...
HG******@nifty.ne.jp (hiwa) wrote in message news:<68**************************@posting.google. com>...
"Jova" <Na**@dotcom.com> wrote in message news:<FR*********************@news4.srv.hcvlny.cv. net>... > Is there a method or way for me to take a couple of char's and make
a sting > out of them .
>
> Example of what I want to do.
>
> String | char
> b = b
> ba = a
> bad = d
couple of char ... char[] couple = {'m', 'f'};
make a string ... String s = new String(couple); // "mf"

Is this what you want?
Another approach would be, where 'b', 'a' and 'd' are chars:

String s = b + a + d + "";

Generally any concatenation involving a string results in a String.
So if you need to a sum, at the same time, you need to isolate it
in brackets:

String s = b + (1+3) + d + "";


I thought it would evaluate left to right, so String s = b + a + d + "";
would be equivalent to

String s = ((( b + a ) + d ) + ""; which is not what was asked for. If

you put the "" first it should work, though. If b, a, and d are int's that is
what it would do. It might treat char specially.

You can also create a StringBuffer, add the chars one at a time, and then
make a String from it.

-- glen

Jul 17 '05 #6

"Phil..." <ry***@ieee.org> wrote in message
news:6xxnb.49857$Fm2.24685@attbi_s04...
my book says left to right also

"Glen Herrmannsfeldt" <ga*@ugcs.caltech.edu> wrote in message


(snip)
I thought it would evaluate left to right, so String s = b + a + d + "";
would be equivalent to

String s = ((( b + a ) + d ) + ""; which is not what was asked for. If
you put the "" first it should work, though. You can also create a StringBuffer, add the chars one at a time, and then make a String from it.


I did test it with char's before "" and it does add the value instead of
concatenating as strings, as left to right says it should.

My favorite was something like:

System.out.println( 2 + "+" +2+" equals " +2+2);

Personally, I think overloading the + operator was a bad idea. Notice that
Java doesn't allow user operator overloading, as users might apply operators
in confusing ways. Then again, the PL/I string concatenation operator, ||,
was already taken.

The awk concatenation operator, nothing at all, might have worked, though.

-- glen
Jul 17 '05 #7
doesn't c++ overload + for strings
"Glen Herrmannsfeldt" <ga*@ugcs.caltech.edu> wrote in message
news:JEBnb.52612$e01.129874@attbi_s02...

"Phil..." <ry***@ieee.org> wrote in message
news:6xxnb.49857$Fm2.24685@attbi_s04...
my book says left to right also

"Glen Herrmannsfeldt" <ga*@ugcs.caltech.edu> wrote in message
(snip)
I thought it would evaluate left to right, so String s = b + a + d + ""; would be equivalent to

String s = ((( b + a ) + d ) + ""; which is not what was asked for. Ifyou put the "" first it should work, though. You can also create a StringBuffer, add the chars one at a time, and then make a String from it.


I did test it with char's before "" and it does add the value instead of
concatenating as strings, as left to right says it should.

My favorite was something like:

System.out.println( 2 + "+" +2+" equals " +2+2);

Personally, I think overloading the + operator was a bad idea. Notice

that Java doesn't allow user operator overloading, as users might apply operators in confusing ways. Then again, the PL/I string concatenation operator, ||, was already taken.

The awk concatenation operator, nothing at all, might have worked, though.

-- glen

Jul 17 '05 #8

"Phil..." <ry***@ieee.org> wrote in message
news:aVBnb.36833$mZ5.184610@attbi_s54...
doesn't c++ overload + for strings


(big snip)

Well, Java tends to borrow from C more than C++.

-- glen
Jul 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Andreas Müller | last post: by
7 posts views Thread by techno | last post: by
3 posts views Thread by Ling Chen Wu | last post: by
33 posts views Thread by Jordan Tiona | last post: by
14 posts views Thread by gustavo | last post: by
33 posts views Thread by Michael B Allen | last post: by
reply views Thread by Saiars | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.