Difference between "char" and "String" in Java
char
is one character. String
is zero or more characters.
char
is a primitive type. String
is a class.
char c = 'a';
String s = "Hi!";
Note the single quotes for char
, and double quotes for 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
.