为什么stringbuilder在使用空字符后停止添加元素? [英] Why stringbuilder stops adding elements after using the null character?

查看:426
本文介绍了为什么stringbuilder在使用空字符后停止添加元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用空字符'\\\'时,stringbuilder将停止添加新元素。

When i am using the null character '\u0000', stringbuilder will stop appending new elements.

例如:

StringBuilder _stringBuilder = new StringBuilder();
_stringBuilder.append('\u0000');
_stringBuilder.append('a');
System.out.println("."+_stringBuilder+".");

返回

. 

我知道null值不应该被打印(或打印, )但是在这种情况下,为什么stringbuilder不能添加更多的元素?

I understand that the null value should not be printed (or printed like if it was a null String value) but in this case, why does stringbuilder is failing to add more elements ?

注意:我在ubuntu上使用jdk 1.6.0_38。

Note: I am using jdk 1.6.0_38 on ubuntu.

推荐答案

空字符是一个保留字符,表示字符串的结尾,因此如果你打印了 \\\ ,不会打印任何内容。

The null character is a reserved character that indicates the end of the string, so if you print something followed by \u0000, nothing else after it will be printed.

为什么stringbuilder会停止添加元素使用空字符?这不是真正的java,它是你的终端,将 \\\ 作为字符串的结尾。

Why stringbuilder stops adding elements after using the the null character? It's not really java, it is your terminal that treats \u0000 as the end of the string.

有人说,使用Windows的输出可以是 .a。(我没有测试它),这是因为Windows终端工作不同比基于Unix的系统终端。我很确定,如果你在一个OSX机器上运行这个代码,你将获得与你在linux上获得的输出相同的输出

As someone says, with Windows the output can be .a. (i did not test it), this is because windows terminal works differently than Unix-based systems terminal. I'm pretty sure that if you run this code on a OSX machine you will get the same output as the one you get on linux

这篇关于为什么stringbuilder在使用空字符后停止添加元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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