,
Strings are not a primitive data type and strings are objects of class String.
They have been built this way primarily because a large number of methods can be implemented for use if string is a class. That way coding regarding strings is much easier.
If you really want to implement it as a primitive data type, go ahead and create an array of characters. but then you wont be able to utilize all the string related methods in JDK
Regards,
Prime
since java is purely a object oriented language here each object is associated with classes and string is also class, so in order order to use a string data type we have to include a file called since its contains all functions data types on string.. the main reason is to give data security
If you mean in Java: no, it is a class. However, the Java language has built-in support for this data type, so that in many cases it SEEMS as a primitive. For example, you can create a String object with a command like:
String x = "abc";
instead of using the "new" operator. However, internally, Java will do the equivalent of using the "new" operator.
I would guess that one reason is that strings can get quite large, so it wouldn't be convenient to store them on the stack; better store them on the heap together with other objects. There are probably other reasons for this decision (not to make them primitive data types) as well.
String - is primitive data typestring - is user defined data type
Yes you can store non primitive data type variables in an array. String is a non primitive data type. You can declare a string array as: String a[]=new String[10];
Depends on the context of the question you were asking from, there are 2 distinct answers: Yes and NO. In the narrowest definition, any array is NOT a primitive data type in C#. Hence a string array is NOT a primitive data type in that context. A string itself, however, is a primitive data type. Some developers would like to extend the definition of "primitives" into the arrays, collections, and Enumeration. Thus, in this context, an array of string IS a primitive data type.
Even in languages where string is a type, it is still an array of characters. A computer can not represent a string as a primitive type. That said, the difference between using the programming language string object or an array or list if characters will differ based on language. Though in most languages which offer a string type, it would mean that you'd have to implement all the functions provided for you by the type on your own. A string object class simply provides a series of utility functions to manipulate a character array within.
A std::string is an object that encapsulates an array of type char whereas a C-style string is a primitive array with no members. A std::string is guaranteed to be null-terminated but a C-style string is not.
String - is primitive data typestring - is user defined data type
String is not primitive data. Only char,int,double,and boolean are!
Yes you can store non primitive data type variables in an array. String is a non primitive data type. You can declare a string array as: String a[]=new String[10];
Depends on the context of the question you were asking from, there are 2 distinct answers: Yes and NO. In the narrowest definition, any array is NOT a primitive data type in C#. Hence a string array is NOT a primitive data type in that context. A string itself, however, is a primitive data type. Some developers would like to extend the definition of "primitives" into the arrays, collections, and Enumeration. Thus, in this context, an array of string IS a primitive data type.
The difference between 'a' and "a" anywhere in Java is that 'a' is a primitive char type, while "a" is a String object.
Even in languages where string is a type, it is still an array of characters. A computer can not represent a string as a primitive type. That said, the difference between using the programming language string object or an array or list if characters will differ based on language. Though in most languages which offer a string type, it would mean that you'd have to implement all the functions provided for you by the type on your own. A string object class simply provides a series of utility functions to manipulate a character array within.
A std::string is an object that encapsulates an array of type char whereas a C-style string is a primitive array with no members. A std::string is guaranteed to be null-terminated but a C-style string is not.
Yes. A single-quoted literal must be a valid character (byte or char) type. It is not a String type. There is no such thing as a single-quoted String literal. 'A' - evaluates to the primitive char type "A" - evaluates to a String type 'ABC' - causes compiler error because it isn't a single character
Not directly. A String is an object, and a double is a primitive data type. To do the conversion you must first convert the String to a Double object (note the capital D in double), then convert that object to a double data type (lowercase d in double). Double is an object, double is a primitive data type. Here's a class that will convert a String to a double:public class StringToDouble{public static void main (String[] arguments) {String s = "100.00";double d = Double.valueOf(s.trim()).doubleValue();System.out.println("double d = " + d);}}
An array is a primitive data type. It is the element type that may or may not be primitive.
primitive non primitive
A primitive data type is built into the language - int, char, long, etc. A non-primitive data type is am abstract data type that is built out of primitive data types - linked list, queue, stack, etc.