[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Char[] to String

Posted on 2004-10-09
5
Medium Priority
?
228 Views
Last Modified: 2010-03-31
How can I convert Char[] to a String object? I try .toString() but that returns its memory address.
0
Comment
Question by:jtcy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12266335
String str=new String((byte[])charArray);
0
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 80 total points
ID: 12266375
char []charArray=new {'H','E','L','L','O'};
String str =new String(charArray);

            ( or)

String str =new String((byte[]charArray);
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12266379
Use SKs' solution, however, here's the easiest technic to remember (in terms of how it works):

String str = "";
for ( int i =0; i<charArray.length; i++ )
    str += charArray [i];

gL,
[r.D]
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 12266676
Don't use DrWarezz's solution.  For string contcationation, Java internally uses a String buffer.  So DrWarezz's solution will compile to approxamatly:
String str = "";
for ( int i =0; i<charArray.length; i++ ) {
    buff=new StringBuffer(str);
    buff.append(charArray [i]);
    str=buff.toString();
}


The String class is actually implemented internally as a character array. So use sudhakar_koundinya's answer.  When you use the
  String str =new String(charArray);
constructor.  The String class will copy your character array into its character array.
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12266693
:o\  lol - woops. Thanks MM.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question