“”之间的区别是什么,和“ “,以及如何用char来测试前者? [英] What is the difference between "" and " ", and how do I test the former in terms of a char?

查看:128
本文介绍了“”之间的区别是什么,和“ “,以及如何用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屋!

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