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.