• 0

Java arrays


Question

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

  • 0

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

  • 0

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

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.