注:关于 float 型和 double 型的区别,以及 char 型和 String 型的不同,在 wiki 中有相关的总结,小伙伴们可以去查看哦~~
注:关于 float 型和 double 型的区别,以及 char 型和 String 型的不同,在 wiki 中有相关的总结,小伙伴们可以去查看哦~~是在哪里有,没有找到,
注:关于 float 型和 double 型的区别,以及 char 型和 String 型的不同,在 wiki 中有相关的总结,小伙伴们可以去查看哦~~是在哪里有,没有找到,
2016-03-17
参见:http://stackoverflow.com/questions/10430043/difference-between-char-and-string-in-java
char is one character. String is zero or more characters.
// char是一个字母,String可以有0个或多个字母(汉字)
char is a primitive type. String is a class.
// char是一个原始类型,String是一个类。
char c = 'a'; String s = "Hi!";
// 这是一个例子,由此可见char里面能放一个字母,String里面可以放多个字母(两个字母+一个符号)
Note the single quotes for char, and double quotes for String.
// char用单引号,String用双引号
// 再附上另外两个答案:
char means single character. In java it is UTF-16 character. String can be thought as an array of chars.
So, imagine "Android" string. It consists of 'A', 'n', 'd', 'r', 'o', 'i' and again 'd'characters.
char is a primitive type in java and String is a class, which encapsulates array of chars.
In layman's term, char is a letter, while String is a collection of letter (or a word). The distinction of ' and " is important, as 'Test' is illegal in Java.
char is a primitive type, String is a class
举报