简体   繁体   中英

Why does java have a primitive char?

As I've been learning about a few different languages, I've seen that java is the only one with a "char" datatype. For example, charAt() for javascript returns a string whereas in java the method returns a character. Is there a reason for a "character" datatype and why don't other languages use them?

James Gosling told me

Most of the time, if you are using a single character value, you will use the primitive char type.

For example:

char ch = 'a'; 

I would like to say and ask myself

for char a='a'; & String a="a";

How much memory does a char variable takes ?

and

How much memory does a string literal or string object takes ?

If you figure this out , Then this answers your question

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM