0 votes
1 view
in Java by (3.5k points)

I have a char array:

char[] a = {'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'};

My current solution is to do

String b = new String(a);

But surely there is a better way of doing this?

1 Answer

0 votes
by (46.1k points)
Your solution is absolutely correct and very insignificant.

Note, however, that this is a highly unique place: Because String is managed especially in Java, even "foo" is a String. So they require a string into unique chars and join them back is not needed in normal code.

Examine this to C/C++ where "foo" you have a package of chars produced by a zero byte on one side and string on the additional side and many varieties between them due to legacy organizations.

Related questions

0 votes
1 answer
asked Jul 9, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer
+1 vote
2 answers
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...