Home Tutorial Java Corejava Copy char array into string

 
 

Share on Google+Share on Google+
Copy char array into string
Posted on: June 29, 2010 at 12:00 AM
Advertisement
This example will help you to know how to copy array of char data type into a string.

Description:

This tutorial demonstrate how to convert char array into a string. In the following code you will see the String.copyValueOf(charArray, 2, 5) return and creates new array of string and copies the specified characters into it and the String.valueOf(charArray) copy the content of character and convert it into string. The implementation is shown in below example.

Code:

public class CopyCharArrayToString {
  public static void main(String[] args) {
    char[] charArray = 'a''b''c''d''e''f''g''h''i''j' };
    String str = String.valueOf(charArray);
    System.out.println(str);
    str = String.copyValueOf(charArray, 25);
    System.out.println(str);
  }
}

Output:

Download this code

Advertisement

Related Tags for Copy char array into string:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 29, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com