• Post Reply Bookmark Topic Watch Topic
  • New Topic

Arrays of arrays.......

 
Joel Cochran
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a program with two methods, main and a JDBC connection method. I want the connection method to return an array of arrays to main. They are defined as such:

When I compile, I get the following 2 errors:

Is there a problem passing around arrays? Is there some reason my method cannot return an array of arrays? And why does the main statement think I'm trying to declare a variable?
Really
------------------
I'm a soldier in the NetScape Wars...
Joel
 
qionghua yang
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi joel,
Try replacing "return clientInfo[][];" with
"return clientInfo; "
Hope this helps.
qionghua
 
Joel Cochran
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by qionghua yang:
Hi joel,
Try replacing "return clientInfo[][];" with
"return clientInfo; "
Hope this helps.
qionghua

Thanks qionghua, that helped. I had to take an extra step though because the compiler did not like

because it said it was never initialized, so I had to replace it with

and it compiled fine. My problem is that I never know how many elements the array is going to have, so I don't like hard coding the '10'. Is there a way to make the array size variable?
Thanks
------------------
I'm a soldier in the NetScape Wars...
Joel
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, if you need a variable like that try Vector or ArrayList. Of course you would need an ArrayList full of ArrayLists if both need to be variable.
 
Joel Cochran
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hhmmmm... The layout is clientInfo[ row# ][ column# ]. I always know how many columns there are (specified in my SQL statement) so [ column# ] would be constant, I'm just not sure how many [ row# ] will be returned by the SQL statement.
I haven't used either vectors or ArrayList before, so which would you recommend I look into first?
------------------
I'm a soldier in the NetScape Wars...
Joel
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you need it to be synchronized, use ArrayList.
 
qionghua yang
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yet, I agree with Cindy. I have used ArrayList before and I think it is very nice. You can get those nice methods like the size(), get(i), etc.
qionghua
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!