Java中char char(0)的含义是什么? [英] What's the meaning of char zero (0) in Java?

查看:596
本文介绍了Java中char char(0)的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

Java字符串替换和NUL(NULL,ASCII 0)字符?

我正在用Java做一些字符串算法,我注意到无论在哪里我包含一个值为0(零)的字符,它都标志着字符串的结束。像这样:

I'm doing some String algorithms in Java, and i noticed that wherever i include a char with the value of 0 (zero) it marks the end of the String. Like this:

String aString = "I'm a String";
char[] aStringArray = aString.toCharArray();
aStringArray[1] = 0;
System.out.println(new String(aStringArray)); //It outputs "I"

这种行为的原因/原因是什么?

What's the reason/cause of this behaviour?

推荐答案

字符'\ 0'是空字符。它是一个控制字符,终止字符串,这不是字符串在Java中的工作方式(不过它们在C中的工作方式)。

The character '\0' is the null character. It's a control character, and it does not terminate the string, that's not how strings work in Java (that's how they work in C, though.)

这篇关于Java中char char(0)的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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