How do I use an arraylist<object> ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AlarV
    New Member
    • Dec 2008
    • 37

    How do I use an arraylist<object> ?

    I've created a class by using UML, and I have as objects Houses and Owners. I wanted an owner to have more than one houses, so I set navigable association and multiplicity 1...*.

    So in the class an arraylist<house > Houses; has been created. How do I create this array in Main.java?

    I know how to do this with 1 object, e.g.
    Code:
        Owner X=new Owner();
        House myhouse=new House();
        X.setHouses(myhouse);
    but I don't know how to use it with an array.

    Thanks in advance for the replies!
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    #2
    use HashMap<Owner,ArrayLis t<House>>

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      I'm not sure how a HashMap is going to help out here.
      Then again, I'm not sure what the problem is exactly...

      In your Owners class you have a method "setHouses" that takes a House object as a parameter. The "setHouses" method should add the House to the arraylist (or if you like a HashMap) of Houses.

      -Frinny

      Comment

      Working...