1

I am trying to store

int[] a=new int[10];
int[] b=new int[20];
int[] c=new int[30];
int[] d=new int[40];

variables a,b,c,d in an array. I don't know how to do it. For user defined type such as objects of myclass I can create an array of type myclass such as

myclass[] m=new myclass[2];

and store references in this array. I don't know how to do this for primitive data types such as int, char etc

3 Answers 3

3

I am trying to store variables a,b,c,d in an array.

You want a two-dimensional array, which is actually an array of arrays:

int[][] arys = new int[4][];
arys[0] = a; 
arys[1] = b; 
arys[2] = c;
arys[3] = d;
Sign up to request clarification or add additional context in comments.

1 Comment

there is a typo, it should be new int[4][];
2

If you are looking for array of array

int [][] arrayOfArray = { intarray1, intarray2, ..};

So

int [][] arrayOfArray = { a, b, ..};

Update:

int store[][]=new int[4][];
        store[0] = a; 
        store[1] = b; 
        store[2] = c;
        store[3] = d;

6 Comments

is'nt the question about array of references to arrays of ints? or am i confused?
I am trying to store [...] reference of a,b,c,d in an array is what confused me :-)
@Koushik That is fine. OP asked both the questions , If I'm not confused :)
@Koushik lets just say that I have four integer array a,b,c,d as defined above now I want to store a,b,c,d in an array so I can get them via index and use them.
@sᴜʀᴇsʜᴀᴛᴛᴀ I am doing this int[] a=new int[10]; int[] b=new int[20]; int[] c=new int[30]; int[] d=new int[40]; Integer store[]=new Integer[4]; store[0]=a; It is showing error
|
0

You can use Integer or Character or Boolean e.g.:

Integer[] a = new Integer[10];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.