[ACCEPTED]-String datatype in java-types

Accepted answer
Score: 34

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.

Score: 4

It's not a primitive, the String class is an object.

http://download.oracle.com/javase/6/docs/api/java/lang/String.html

0

Score: 2

because it's a class and not a primitive 2 data type. String is effectively an array 1 of characters.

Score: 1

Although the compiler has special support 7 for Strings, 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.

Score: 0

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