aspose file tools*
The moose likes Beginning Java and the fly likes Arrays of arrays....... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Arrays of arrays......." Watch "Arrays of arrays......." New topic
Author

Arrays of arrays.......

Joel Cochran
Ranch Hand

Joined: Mar 23, 2001
Posts: 301
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


Wait a minute, I'm trying to think of something clever to say...<p>Joel
qionghua yang
Ranch Hand

Joined: Oct 31, 2000
Posts: 68
Hi joel,
Try replacing "return clientInfo[][];" with
"return clientInfo; "
Hope this helps.
qionghua
Joel Cochran
Ranch Hand

Joined: Mar 23, 2001
Posts: 301
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

Joined: Sep 29, 2000
Posts: 8521
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.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Joel Cochran
Ranch Hand

Joined: Mar 23, 2001
Posts: 301
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

Joined: Sep 29, 2000
Posts: 8521
Unless you need it to be synchronized, use ArrayList.
qionghua yang
Ranch Hand

Joined: Oct 31, 2000
Posts: 68
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
 
 
subject: Arrays of arrays.......