且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将字符数组转换回字符串?

更新时间:2023-01-30 17:36:29

不,该解决方案绝对正确,而且非常简单.

No, that solution is absolutely correct and very minimal.

但是请注意,这是一种非常不寻常的情况:因为 String 在 Java 中是专门处理的,即使 "foo" 实际上是一个 String>.因此,在普通代码中不需要将 String 拆分为单独的 char 并将它们连接回来.

Note however, that this is a very unusual situation: Because String is handled specially in Java, even "foo" is actually a String. So the need for splitting a String into individual chars and join them back is not required in normal code.

将其与 C/C++ 进行比较,其中 "foo" 您有一组 char 以一侧的零字节和 string 结尾> 另一方面,它们之间的许多转换都是遗留方法.

Compare this to C/C++ where "foo" you have a bundle of chars terminated by a zero byte on one side and string on the other side and many conversions between them due do legacy methods.