Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about lists

 
Ran Takad
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this my first post here, i hope you can help me
my question is :
i have two Arraylist one for rooms (for example) and the other for house, when i want to add a room to specific house i need to find that house in the houselist first, then i need to have internal list inside houselist to add the room to that house (house1[room1,room2,room3],house2[room1]). but i don't know how to implement a list inside a list? any idea?
thanks in advance
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have classes Room and House, right php php? And a house has zero or more rooms:

If you aren't using the current version of Java, that field would be defined by:

By the way, have you done the tutorial on collections: http://java.sun.com/docs/books/tutorial/collections/index.html ?
 
Campbell Ritchie
Sheriff
Posts: 48635
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome on board.

You will have to change your displayed name, because there is a strict policy about user names here.

You should find it quite easy to implement the data structure you suggest. You do exactly what you ahve suggested on screen. Just bite the bullet and go for it, and see whether it works.

I presume that as a newby you are using J2SE5.0? If so, you will want to use your ArrayLists in a generic fashion. You might have three classes:

CR
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Campbell says, your display name doesn't satisfy our site policy. A display name needs to be a real (sounding) first name, a space, and a last name. You can change yours here. Thanks for your understanding and prompt attention.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic