File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

storeing 2d array in arraylist?

 
sudde gameeef
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to save 2d array in arraylist and how to print it???


it print the wrong stuff. try running it to see the problem.
 
Greg Charles
Sheriff
Posts: 2984
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

Line 18 won't compile right? So it's not really printing anything.

You've declared your ArrayList to contain 2D arrays of Integers, but then you write code that seems to want to store individual ints in it, and even that's not done exactly right.

I'd start by changing line 6 to:


Then see if you can work that compile error out of there.
 
sudde gameeef
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i jave some question:
1st i am not sure but i hear that when we store 2d array in to list than we dont need loops?
2nd should i used 2d arraylist bc i am using 2d int array?

-------------------------------------------------------------
error is gone now. how can i print the arraylist:
i did this and i think its printing the index values


 
Greg Charles
Sheriff
Posts: 2984
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thing is an Integer is an Object, and a 2D array of Integers taken as a whole is also an Object, just a different kind. You have to decide if you want the elements of the list to be the individual Integers in your array (in your case this is 90 elements), or do you want the elements to be the whole array, so the list only has one element. In the first case, you'd want loops to populate the list, but in the second, you wouldn't. Which form you use depends on your assignment, or in the real word, whichever form will be more useful to the rest of your application.

Printing out a 2D array is going to give you something like: [[Ljava.lang.Integer;@1c78e57 That's probably not what you want, so you will likely need loops to print it out in the form you prefer.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic