loading...

Char Array To String

pakainfocom profile image pakainfo ・1 min read

In this post, I will learn how to convert char array to String in Java. A fresh String should be allocated that display the step by step sequence of characters details in the chars array. Since Simple Data String is immutable in Java Programming, the subsequent updation of the simply character main array does not affect the allocated data strings. we will learn about chars array to strings with an example.

Using String Constructor
The simplest solution is to pass arguments the char array into the data Strings constructor. The data Strings Java constructor intramural uses Arrays.copyOf() function to copy the data contents of the character main array.
// Convert chars array to String in Java
class CharArrayToString
{
public static void main(String[] args)
{
char[] mycharacters = {'P', 'a', 'k', 'a', 'i', 'n', ' ',
'J', 'a', 'y', 'd', 'e', 'e', 'p'};
String resultstr = new String(mycharacters);
System.out.println(resultstr);
}
}

You can visit my Article with More Examples : click here

Posted on by:

pakainfocom profile

pakainfo

@pakainfocom

My name is Angular King. I'm a full-stack developer, entrepreneur and owner of Pakainfo. I live in India and I love to write

Discussion

pic
Editor guide