This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Object[][] or some other data structure?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Object[][] or some other data structure??" Watch "Object[][] or some other data structure??" New topic
Author

Object[][] or some other data structure??

Jas Oberai
Ranch Hand

Joined: Jan 16, 2005
Posts: 231
Hi Friends,
I have classes(A,B..G) and roll numbers.I want to iterate through the data and put them into appropriate classes.Which data structure should i use??because I dont know before hand how many roll numbers might go into a class.I am trying to use a Object array like this:

Oject[][] arr = new Object[7][];

But the problem is I have to specify a "col" dimension,which i dont know and specifying something big impacts the performance.I dont think i can dynamically assign object like this:

Object[0][0] = new Object();
Object[0][1] = new Object();
........
Object[1][0] = new Object();

Or can I?Please help me on this friends.


SCJP 1.4 (88%)<br />SCWCD 1.4 (88%)
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30050
    
149

Jas,
Welcome to JavaRanch!

It sounds like you know there are seven classes, but don't know how may roll numbers there are. So you are correct that you need an array of something. The second level should be a data structure that can grow as needed, like an ArrayList. So now you have:
ArrayList[] arr = new ArrayList[7];


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Object[][] or some other data structure??
 
Similar Threads
How to maintain Parent-Child Data
How to name and access an array which its name is not specified?
Java Help: NullPointerException
Help with AbstractTableModel - Please!!
Reading Complex Map and Collection