Win a copy of Spring in Action (5th edition) this week in the Spring 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
author & internet detective
Posts: 38906
684
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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];
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!