0
Whats the diffrence between char a = "a"; and String a = "a";?
what can i do with char that i cant do with a String please?
3 Respostas
+ 5
char is a primitive data type and you need to use single quotes when initializing it:
char letter = 'a';
String is actually a class.
char also is a numeric type behind the scenes:
letter is also equal to 97, its ascii value (http://www.asciitable.com), and can have mathematical operations performed on it as well as bitwise operations.
letter++;
letter is now equal to 98 or 'b'
+ 2
perfect thanks chaotic i get it.
+ 1
Too vague of a question. Read through java's documentation on the data types. You can manipulate strings in ways that chars cannot.
https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html
https://docs.oracle.com/javase/7/docs/api/java/lang/String.html