[ACCEPTED]-String datatype in java-types
String
isn't a primitive datatype - it's a class, a 4 reference type. Now admittedly it's supported 3 directly in the VM, and there are literals 2 in the language - but it's still not a primitive 1 type.
It's not a primitive, the String class is an object.
http://download.oracle.com/javase/6/docs/api/java/lang/String.html
0
because it's a class and not a primitive 2 data type. String is effectively an array 1 of characters.
Although the compiler has special support 7 for String
s, such as converting string literals 6 into String instances, and performing String 5 concatenation, String is not a primitive 4 type, but a Class. By convention, class 3 names begin in uppercase.
See the JLS section 2 Types,Values and Variables for description of primitive types and 1 reference types.
String is a non premitive data type . You 1 can use String as follows
int monthNumber = 2;
String monthName = "";
switch(monthNumber) {
case 1:
monthName = "January";
break;
case 2:
monthName = "February";
break;
case 3:
monthName = "March";
break;
case 4:
monthName = "April";
break;
}
System.out.println("The month is " + monthName);
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.