General Disarray Posted March 4, 2009 Share Posted March 4, 2009 Hi I need to create an integer array of integers in java, so: int[] array1 = {100,50, 40}; int[] array2 = {500, 250, 240}; then i need an array like int[] both = {array1, array2} so i could then do both[2].[0] = 100; and array2 would then be {100, 250, 240} is this possible? Thanks Link to comment Share on other sites More sharing options...
0 Bookieass Posted March 4, 2009 Share Posted March 4, 2009 You two steps array creation is can be simplified using two dimensional arrays maybe you can look for jagged arrays....... google it, u will find it with tutorial Link to comment Share on other sites More sharing options...
0 JamesCherrill Posted March 4, 2009 Share Posted March 4, 2009 Yes. A Java array can contain other arrays as its members, and those member arrays do not have to be of the same size. ps you can't do both[2].[0] because (a) Java arrays are zero-based; the second element is element 1, and (b) there's no dot between the [][] Link to comment Share on other sites More sharing options...
Question
General Disarray
Hi
I need to create an integer array of integers in java, so:
int[] array1 = {100,50, 40};
int[] array2 = {500, 250, 240};
then i need an array like
int[] both = {array1, array2}
so i could then do
both[2].[0] = 100;
and array2 would then be {100, 250, 240}
is this possible?
Thanks
Link to comment
Share on other sites
2 answers to this question
Recommended Posts