answersLogoWhite

0


Best Answer

,

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

User Avatar

Wiki User

8y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

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

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

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.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

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.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Is string is a primitive type or not?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Is string is primitive or user defined data type?

String - is primitive data typestring - is user defined data type


Can you store non primitive data type in the array list?

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];


Is string arr a non primitive data type?

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.


What are the different issues if a string is implemented as a primitive or as a character array?

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.


What is the difference between a C plus plus string and a C-style string?

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.

Related questions

Is string is primitive or user defined data type?

String - is primitive data typestring - is user defined data type


Where string is primitive data type of string data type?

String is not primitive data. Only char,int,double,and boolean are!


Can you store non primitive data type in the array list?

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];


Is string arr a non primitive data type?

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.


What are the different between'a' and ''a in java string methods?

The difference between 'a' and "a" anywhere in Java is that 'a' is a primitive char type, while "a" is a String object.


What are the different issues if a string is implemented as a primitive or as a character array?

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.


What is the difference between a C plus plus string and a C-style string?

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.


Do single quoted string literals have any characteristics difference from those of double quoted string literals?

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


Is it possible to convert strings in java to double directly?

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);}}


Why arrays are not primitive data type?

An array is a primitive data type. It is the element type that may or may not be primitive.


What are different data type in c?

primitive non primitive


What is different between primitive date type and non primitive data type in c plus plus programming language?

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.