In java is String both primitive data type and object? And does String take more memory than Char data type?
String is a class, an object. string is a primitive. Note the different spelling. char is a single UTF encoded character. [Ss]trings are multiple UTF encoded characters.
And for example: int num = 2; num = 9; --> 2 is destroyed from the memory and 9 is placed instead String name = "me"; name = "get"; ----> the value "me" is not destroyed and stays on the memory but only the reference changes to "get". Is this right? And what are the string values "get" and "me" called ?
This URL is for Java's tutorial: http://docs.oracle.com/javase/tutorial/java/data/index.html
Er. rsmith. I'm not sure string is actually a primitive. It's an object.
farmdawgnation is correct. String is not a primitive. There are 8 primitives: byte, char, boolean, short, int, long, float, double. Except for a 1 or 2 byte String, Strings will take up more bytes than chars. A char is 2 bytes or 16 bits in Java. A String can be any length, like 10, 50 or 1000 characters. @myname: And what are the string values "get" and "me" called ? just that, values.
Join our real-time social learning platform and learn together with your friends!