URGENT! Convert char[] array into a String

Z

ZOCOR

Hi

How do you convert an array of characters (ie char[]) into a String?

consider: char[] data;

I tried: data.toString();

and got a list of memory address when i want a string.

also tried: String str = (String)data; //compile error

Help Urgent

Cheers
ZOCOR
 
P

[private]

ZOCOR said:
Hi

How do you convert an array of characters (ie char[]) into a String?

consider: char[] data;

I tried: data.toString();

and got a list of memory address when i want a string.

also tried: String str = (String)data; //compile error

Help Urgent

Cheers
ZOCOR


String str = String.valueOf(data);
 
S

Sudsy

ZOCOR said:
Hi

How do you convert an array of characters (ie char[]) into a String?

consider: char[] data;

I tried: data.toString();

and got a list of memory address when i want a string.

also tried: String str = (String)data; //compile error

Help Urgent

1. This is not a 24-hour-a-day help desk.
2. Review the javadocs, in particular the constructors for String
(big hint: there's one which takes an argument of char[] )
 
A

Andrew Thompson

Sub: URGENT! Convert char[] array into a String

Do you actually believe that putting URGENT in capitals (or at
all for that matter) in your subject line is going to make people
check the usenet postings, or reply, sooner?

If anything, it will make them not reply at at all.

"Well.. it was urgent, and it's two hours later now,
so it is obniously too late. I won't bother.."
How do you convert an array of characters (ie char[]) into a String?

consider: char[] data;

I tried: ...

Did you try checking the Javadocs?

There is one String constructor that might interest you..
(And I will point out that checking the Javadocs is quicker
than asking on usenet.)

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
 
A

Alex Kizub

String abc=new String(data);
You just stopped look over too soon.
I suggest for you to write random generator from all java key words and
use it in the future.
Use it as input stream for java compiler and use all results without
syntax errors.

Alex Kizub.
 
A

Abrasive Sponge

Sudsy said:
ZOCOR said:
Hi

How do you convert an array of characters (ie char[]) into a String?

consider: char[] data;

I tried: data.toString();

and got a list of memory address when i want a string.

also tried: String str = (String)data; //compile error

Help Urgent


1. This is not a 24-hour-a-day help desk.


Yes, it is, why not? Are there times when the internet is not open?
I agree that the newsgroups shouldn't do projects for students but
showing some direction is not so tough.
 
A

Abrasive Sponge

Alex said:
String abc=new String(data);
You just stopped look over too soon.
I suggest for you to write random generator from all java key words and
use it in the future.
Use it as input stream for java compiler and use all results without
syntax errors.

Alex Kizub.

Compile-time exception I believe.
new String(byte[] b) accepts bytes, the O.P. has a char[].
 
A

Alex Kizub

Of course I should quote all necessary information.
Tt was in previous post:
consider: char[] data;

So, I assume that this url
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#String(char[])
proves my point.

Alex Kizub.
P.S. Anyway it was not about to answer. It was about question.

Abrasive said:
Alex said:
String abc=new String(data);
You just stopped look over too soon.
I suggest for you to write random generator from all java key words and
use it in the future.
Use it as input stream for java compiler and use all results without
syntax errors.

Alex Kizub.

Compile-time exception I believe.
new String(byte[] b) accepts bytes, the O.P. has a char[].
 
S

Steve Sobol

Abrasive said:
Yes, it is, why not? Are there times when the internet is not open?
I agree that the newsgroups shouldn't do projects for students but
showing some direction is not so tough.

Usenet technical newsgroups can be used as a 24-hour-a-day help desk, but
consider it a help desk staffed by volunteers who often have more important
things to do, and don't get pissed off when someone doesn't answer you
immediately (or at all).

No one has a $DEITY-given right to an answer on Usenet.
 
A

Anks

ZOCOR said:
Hi

How do you convert an array of characters (ie char[]) into a String?

consider: char[] data;

I tried: data.toString();

and got a list of memory address when i want a string.

also tried: String str = (String)data; //compile error

Help Urgent

Cheers
ZOCOR

char[] data = new char[]{'a', 'b', 'c'};
String str = new String(data);

That's it.

Be happy :)
 
A

Andrew Thompson

Sudsy said:
ZOCOR wrote: ...
How do you convert an array of characters (ie char[]) into a String?
...
1. This is not a 24-hour-a-day help desk.

Yes, it is, why not?

Is that a question, or an argument that usenet *is* a
24-hour-a-day help desk?
I agree that the newsgroups shouldn't do projects for students but
showing some direction is not so tough.

Which is why Sudsy added '2.', I will reprint it,
as you apparently missed it.

(trimmed, reinstated)
2. Review the javadocs, in particular the constructors for String
(big hint: there's one which takes an argument of char[] )

[ Personally, I thought that answer approached "where's my spoon?",
but my own answer was not far short of it. ]

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
 
A

Abrasive Sponge

Andrew said:
Sudsy said:
ZOCOR wrote:
..
How do you convert an array of characters (ie char[]) into a String?
..
1. This is not a 24-hour-a-day help desk.

Yes, it is, why not?


Is that a question, or an argument that usenet *is* a
24-hour-a-day help desk?

It's an argument that the usenet is that and more.
I agree that the newsgroups shouldn't do projects for students but
showing some direction is not so tough.


Which is why Sudsy added '2.', I will reprint it,
as you apparently missed it.

(trimmed, reinstated)
2. Review the javadocs, in particular the constructors for String
(big hint: there's one which takes an argument of char[] )


[ Personally, I thought that answer approached "where's my spoon?",
but my own answer was not far short of it. ]

:)
 
T

Tony Morris

The "URGENT"-ness is often a put-off.
What is urgent to you (the OP), may not be urgent to me or the rest of the
Usenet crowd.
We don't care if you fail your assignment (actually, I do - the less
incompetence in this industry, the easier my job is).
Screaming "urgent" also implies that you are expecting a prompt response,
when you should be expecting "****-all", and if you do receive a response,
be grateful.
 
Z

ZOCOR

ZOCOR said:
Hi

How do you convert an array of characters (ie char[]) into a String?

consider: char[] data;

I tried: data.toString();

and got a list of memory address when i want a string.

also tried: String str = (String)data; //compile error

Help Urgent

1. This is not a 24-hour-a-day help desk.
2. Review the javadocs, in particular the constructors for String
(big hint: there's one which takes an argument of char[] )

It is interesting to note how all the old farts react to urgent postings. It
seems as though the old farts have forgotten one of the important rules of
conduct on a newsgroup. That is, if you do not have anything of value to add
in response to a posting, DO NOT RESPOND. All you are doing is adding more
noise to an already busy newsgroup. You have been warned.

ZOCOR
 
S

Stefan Schulz

It is interesting to note how all the old farts react to urgent
postings. It seems as though the old farts have forgotten one of the
importantrules of conduct on a newsgroup. That is, if you do not have
anything of valueto add in response to a posting, DO NOT RESPOND. All
you are doing is adding more noise to an already busy newsgroup. You
have been warned.

Ok, i'll bite. :) Your posting was by far the most off-topic and useless
one
in this Thread.

HAND
Stefan
 
T

Thomas Weidenfeller

Stefan said:
Ok, i'll bite. :) Your posting was by far the most off-topic and
useless one
in this Thread.

But his "mail" was certified as "virus free". :)

/Thomas
 
A

Alex Hunsley

ZOCOR said:
ZOCOR said:
Hi

How do you convert an array of characters (ie char[]) into a String?

consider: char[] data;

I tried: data.toString();

and got a list of memory address when i want a string.

also tried: String str = (String)data; //compile error

Help Urgent

1. This is not a 24-hour-a-day help desk.
2. Review the javadocs, in particular the constructors for String
(big hint: there's one which takes an argument of char[] )


It is interesting to note how all the old farts react to urgent postings. It
seems as though the old farts have forgotten one of the important rules of
conduct on a newsgroup. That is, if you do not have anything of value to add
in response to a posting, DO NOT RESPOND. All you are doing is adding more
noise to an already busy newsgroup. You have been warned.

ZOCOR

I wholeheartedly agree that people should respond with things of value.
And pointing out that writing "urgent" is considered rude is valuable,
because then you might not bother doing it next time.

Also, I'll take this chance to point out that alienating the people you
expect to help you is not the smartest of maneuvres.

alex
 
A

Alex Hunsley

ZOCOR said:
ZOCOR said:
Hi

How do you convert an array of characters (ie char[]) into a String?

consider: char[] data;

I tried: data.toString();

and got a list of memory address when i want a string.

also tried: String str = (String)data; //compile error

Help Urgent

1. This is not a 24-hour-a-day help desk.
2. Review the javadocs, in particular the constructors for String
(big hint: there's one which takes an argument of char[] )


It is interesting to note how all the old farts react to urgent postings. It
seems as though the old farts have forgotten one of the important rules of
conduct on a newsgroup. That is, if you do not have anything of value to add
in response to a posting, DO NOT RESPOND. All you are doing is adding more
noise to an already busy newsgroup. You have been warned.

Just out of interest, what is the meaning of "you have been warned?".
What, exactly, will happen to usenet or us if things continue exactly as
they are, with rude scamps having their rudeness pointed out to them?
 

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,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top