“”之间的区别是什么,和“ “,以及如何用char来测试前者? [英] What is the difference between "" and " ", and how do I test the former in terms of a char?
问题描述
在Java中,(空引号)和(具有单个空格的引号)之间的区别是什么,如何使用 char
?
代表空字符串。
为空,它包含一个空格字符。
按照 char
来测试前者,因为没有字符:以 String
:它是长度为零的 String
, String.equals()
返回 c>
char
数组,例如: char noChars [] = new char [0];
String str = new String(noChars);
//现在str是空字符串
In Java, what is the difference between "" (empty quotes) and " " (quotes with a single space) and how do I test the former in terms of a char
?
""
represents the empty string. " "
is not empty, it contains a single space character.
You can't test the former in terms of a char
, as there are no characters: test for it in terms of a String
: it is the String
of length zero, and String.equals("")
returns true
for the empty string.
Or in terms of char
arrays, the empty string corresponds to the char
array of length zero, e.g.:
char noChars[] = new char[0];
String str = new String(noChars);
// now str is the empty String
这篇关于“”之间的区别是什么,和“ “,以及如何用char来测试前者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!