This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

storeing 2d array in arraylist?

 
Greenhorn
Posts: 19
  • 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.
 
Sheriff
Posts: 3034
12
Mac IntelliJ IDE Python VI Editor Java
  • 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
  • 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: 3034
12
Mac IntelliJ IDE Python VI Editor Java
  • 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.
 
There’s no place like 127.0.0.1. But I'll always remember this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!