为什么字符串在java中以null字符终止? [英] why strings are terminated with null character in java?

查看:208
本文介绍了为什么字符串在java中以null字符终止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我已经读过字符串在java中以null字符终止。但是为什么它是必要的,因为字符串的长度已经由sting类的长度变量维护了?所以这对我来说有点奇怪。请有人向我澄清。

Today I have read that strings are terminated with null character in java. But why is it necessary since length of the string is already maintained by the length variable of the sting class ? So it's kind of strange thing to me. Please someone clarify it to me.

谢谢

推荐答案

Java字符串不是空终止。它们以长度的长度结束。您可以将 \0 设置为Java字符串的最后一个字符,但这不会自动终止该字符串。 12< \0> 45 的长度仍然是5,而不是C中的2。

Java strings are not null terminated. They end with the length in length. You can make a \0 the last character of a Java string, but that doesn't automatically terminate the string. The length of 12<\0>45 would still be 5 and not 2 as in C.

这篇关于为什么字符串在java中以null字符终止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆