Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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 (46k 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
+1 vote
2 answers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...