answersLogoWhite

0

Of course they maybe used together. (do not understand what the word program meant in the question context)

However, do not put them together in an array. In fact, any collection, including an array, should hold only 1 kind of objects. (the word kind means a base class and its derived subclasses, the same interface, or the same primitive types).

Putting more than 1 kind of objects in an array is making troubles for yourself, putting more than one class of objects in an array is an acceptable practice.

Another thing to look out for, if a primitive type is always go with a reference type, or most of time, being used, or being passed to another method, you may have a new class to be designed. You should put them together into a new class.

If you have a method need to return a primitive and a reference type, you may have another class design to do as well, or the method is doing too many things (one is the principle!). 1 pair of int and Person may not be a problem.

But when you have more than 10 pairs... Do you have 2 arrays, one to hold the integers, one to hold Person? Or you have 1 array to hold both (the odd element is always the int, and the even is the Person - big mistake). Now just image that, oh by the way, you will need a String (message text) go with the int and the Person....

User Avatar

Wiki User

13y ago

What else can I help you with?

Continue Learning about Engineering

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


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.


When an array contains values other than primitive data types is it considered a control array?

Only if the non-primitive data types are actually controls, such as an array of label controls, or an array of edit boxes. However, a control array is still an array. The only difference is that the values will likely be resource handles (objects that refer or point to the actual object which will be stored elsewhere in memory) rather than an actual value itself. That is, an array of primitive data types stores the actual value in the array itself.


Should element in an array must be of primitive data type?

No, it can be array, structure or union as well.


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.

Related Questions

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


What is meant by the term array?

Arrays are objects in Java that store multiple variables of the same type. Arrays can hold either primitives or object references, but the array itself will always be an object on the heap, even if the array is declared to hold primitive elements. In other words, there is no such thing as a primitive array, but you can make an array of primitives. Arrays are declared by stating the type of element the array will hold, which can be an object or a primitive, followed by square brackets to the left or right of the identifier. Declaring an array of primitives: int[] Values; // brackets before name (recommended) int Values []; // brackets after name (legal but less readable) // spaces between the name and [] legal, but bad Declaring an array of object references: Ferrari[] Ferraris; // Recommended Ferrari Ferraris[]; // Legal but less readable When declaring an array reference, you should always put the array brackets immediately after the declared type, rather than after the identifier (variable name). That way, anyone reading the code can easily tell that, for example, Values is a reference to an int array object, and not an int primitive.


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.


Non primitive data type?

Struct or array.


Is array list value type or reference type?

Arrays are reference type. array values are always pass by reference.


When an array contains values other than primitive data types is it considered a control array?

Only if the non-primitive data types are actually controls, such as an array of label controls, or an array of edit boxes. However, a control array is still an array. The only difference is that the values will likely be resource handles (objects that refer or point to the actual object which will be stored elsewhere in memory) rather than an actual value itself. That is, an array of primitive data types stores the actual value in the array itself.


What is the difference between primitive and non primitive data structure?

A primitive data structure is generally a basic structure that is usually built into the language, such as an integer, an array or a linked-list.A non-primitive data structure is built out of primitive data structures linked together in meaningful ways, such as a binary search tree, AVL Tree, Hashtable, etc.


Should element in an array must be of primitive data type?

No, it can be array, structure or union as well.


Is array a primitive data structure?

No, it's not. But it can be based on primitive data types (int, char, long, double and so on).


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.


Are arrays objects?

Yes. Arrays are objects in Java that store multiple variables of the same type. Arrays can hold either primitives or object references, but the array itself will always be an object on the heap, even if the array is declared to hold primitive elements. In other words, there is no such thing as a primitive array, but you can make an array of primitives


How do you accept an array in java?

Arrays are objects in Java that store multiple variables of the same type. Arrays can hold either primitives or object references, but the array itself will always be an object on the heap, even if the array is declared to hold primitive elements. In other words, there is no such thing as a primitive array, but you can make an array of primitives. Arrays are declared by stating the type of element the array will hold, which can be an object or a primitive, followed by square brackets to the left or right of the identifier. Declaring an array of primitives: int[] Values; // brackets before name (recommended) int Values []; // brackets after name (legal but less readable)