java是否将字符串定义为空终止? [英] Does java define string as null terminated?

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

问题描述

正如我的标题所暗示的,这是一个理论问题.我想知道如果 java 将字符串定义为空终止.

As my title suggests, it's a theoretical question. I'd like to know that if java defines string as null terminated.

推荐答案

Java 字符串不像在 C 或 C++ 中那样以空字符终止.尽管 java 字符串在内部使用 char 数组,但其中没有终止 null.String类提供了一个叫做length的方法来知道字符串中的字符数.

Java strings are not terminated with a null characters as in C or C++. Although java strings uses internally the char array but there is no terminating null in that. String class provides a method called length to know the number of characters in the string.

这是简单的代码及其调试器内容:

Here is the simple code and its debugger contents:

public static void main(String[] args) {
    String s = "Juned";
    System.out.println(s);
}

调试器截图:

这篇关于java是否将字符串定义为空终止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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