Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

Convert charArray to String

In this section, you will learn how to convert chararray to String .

Ads

Tutorials   
Ads

Convert charArray to String

     

Lets see how to convert charArray to String. 

Code Description:

In this program we have taken an Array of characters as
char [] array = { '(','B','o','n','j','o','u','r',' ','m','a','d','a','m','e',')' }; and we have passed it to a String. Hence we get the following output as shown below.

Here is the code of this program:

public class charArraytoStr{
  public static void main(String args[]){
  char [] array = '(','B','o','n','j','o','u','r',' ','m','a',
'd','a','m','e',')' };
  String s = new String(array);
  System.out.println(s);  
  }
}

Output of the program:

C:\unique>javac charArraytoStr.java

C:\unique>java charArraytoStr
(Bonjour madame)

Download this example.

Advertisements

Share on Google+Share on Google+

Convert charArray to String

Posted on: August 9, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Convert charArray to String  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Sreechand
May 27, 2012
without initializing

what if i want to convert a character array to string without initializing the array when declared and later i will assign values to the array later in the code before converting in into string

Ads

 

Ads