Computer Science, asked by bsvasanth567, 11 months ago

Can we use different data type values in a single array?

Answers

Answered by DEVlL
0

Answer:

Yes

Explanation:

We can use different data type value in a single array when declare the array as Object. An element inside an array can be of any type, and different element of the same array can be of different types :

Answered by shilpa85475
0

Yes, we can store multiple data types in one array.

EXPLANATION:  

  • An array is a collection of values in one unit. Each slot in an array can hold one value. Each value is called an element. And each element has a numeric position in the array which is known as its index.
  • An element inside an array can be of any type (string, Boolean etc). Also, we can have elements that are of different data types in a single array.  
  • In Java, we declare a variable which holds an array.

Then create an array object and assign it to array variable that is declared.

int abc()    //declaring a variable

int abc() = new int[10]

Different data types in one array:

var xyz = new Array(); // creation of an array

xyz[0] = ”COLLECTION”; // String literal at index 0

xyz[1] = 50; // real number at index 1

xyz[2] = true; //Boolean value .

Similar questions