+ 6
char is a primitive type, and it can hold a single character. String is instead a reference type, thus a full-blown object. It can hold any number of characters (internally, String objects save them in a char array). Primitive types in Java have advantages in term of speed and memory footprint. But they are not real objects, so there are some possibilities you lose using them. They cannot be used as Generic type parameters, they could not have methods or fields, and so on. Source: http://stackoverflow.com/questions/10430043/difference-between-char-and-string-in-java In short, using primitive types (i.e. char) have an advantage as far as speed and memory goes (smaller memory footprint as mentioned above). You would also benefit by checking out how autoboxing works in java.
23rd Apr 2017, 11:57 PM
Billy Tsouvalas