473,382 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How do I use an arraylist<object> ?

37
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.
Expand|Select|Wrap|Line Numbers
  1.     Owner X=new Owner();
  2.     House myhouse=new House();
  3.     X.setHouses(myhouse);  
but I don't know how to use it with an array.

Thanks in advance for the replies!
Jan 2 '10 #1
2 1840
sukatoa
539 512MB
use HashMap<Owner,ArrayList<House>>
Jan 2 '10 #2
Frinavale
9,735 Expert Mod 8TB
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
Jan 5 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: ASP Yaboh | last post by:
I have an ArrayList of data gathered from a database. I want to create a web page from this data by creating a <table>, each cell in each row displays the appropriate data. One of those cells in...
4
by: colson | last post by:
Hi, If I have a class A, and a List<List<object>> containing instances of A. How do I explicitly cast List<List<object>> as List<List<A>>?
3
by: Iwanow | last post by:
Hello! My goal is to develop a program that opens a bitmap, copies its pixels to an ArrayList in order to perform some complex calculations (edge detection, Hough transform etc.), and save...
13
by: Murat Ozgur | last post by:
Hello, Is there any difference between ArrayList and List<object? Which one should I use ? Thanks.
3
by: Samuel R. Neff | last post by:
You can you program against generic interfaces generically? For example, how can I make the following code which works for the non-generic interface also work for the generic counterparts? ...
2
by: Jeff | last post by:
..NET 2.0 I'm wondering if it is possible set the DataGridView.DataSource to a List<objectcollection. Where object is a class derived from the object class. If it's possible then my question...
10
by: lpinho | last post by:
Hi all, I have a class (named for the example myObject) that can be of several types (int, string, float, etc), instead of using a object to define it's type I used a generic. public class...
5
by: Tony Johansson | last post by:
Hello! I have the following simple program below. What is the problem when I get runtime error for "Failed to compare two elements in the array ?" using System; using...
4
by: =?Utf-8?B?SkI=?= | last post by:
Hello List<Tis said to be more powerful than ArrayLists but if you have something like this: List<intmylst = new List<>; myList.Add("Joe"); myList.Add(25); the list doesn't seem to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.