• Post Reply Bookmark Topic Watch Topic
  • New Topic

2d ArrayList help !!  RSS feed

 
Mick Jones
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am trying to create a 2D array list which I believe I have done correctly, but when the program runs it just outputs the info from the second set of add().

My current output is:

107
107

I want it to print out the ID of each product, like so:

106
107

Anyone have any ideas? This should be so simple and I am tearing my hair out

Please help


 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no such thing as a 2D ArrayList; there is only a List of Lists. There is nothing 2D about it.

You are adding your List as index 0, then adding the same List again as index 1. So you only have one List in the ouiter List, only it appears twice.
 
Naga Niranjan
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should reinitialize prodArrayCol after adding it to prodArrayRow.

Thanks,
Niranjan
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe declaring a new List would be preferable to re-initialising. If you search this forum you will find ways to do that, even including creating an anonymous class!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!