473,406 Members | 2,451 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,406 software developers and data experts.

Can someone help me create an array of objects??

Hi,
I've created a class called Person which has parameters "First_name, Surname, month (of birth), day (of birth)". This class creates person objects fine but now i want to create another class which will take these objects and store them in an array. As i dont know how many Person objects i will create i can't make a predefined array size.

Any help would be very grateful,

Thanks
Apr 27 '07 #1
3 2062
JosAH
11,448 Expert 8TB
Store them in a List<Person> instead. Read the API docs of the ArrayList
and LinkedList classes; they're both implementations of the List interface.

kind regards,

Jos
Apr 27 '07 #2
Thanks for that, I have now created an arraylist called people, but i have come across a problem. This is my code :

import java.util.*;
import java.util.ArrayList.*;

public class People
{

public static void main (String[] args)
{
ArrayList<Person> people = new ArrayList<Person>();
people.add( Person.First_name );
people.add( Person.Surname );


}
}

When I try to compile the code it tells me i cant reference the non-static variable First_name into a static context. I know i'm not allowed to do this but i cant see how to over come it. I cant change either of my methods from static to non-static and visa versa. Any ideas??
Apr 27 '07 #3
JosAH
11,448 Expert 8TB
Do you want me to delete this thread because your other thread is basically
a duplicate of this one and the other thread gives you all the information needed.

kind regards,

Jos
Apr 27 '07 #4

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

Similar topics

6
by: Helmut Giese | last post by:
Hello out there, I am a rather experienced C programmer. However, today I got a javascript assignment because someone left (something like: "You're a great programmer - you'll handle this.") and I...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
5
by: Mountain Bikn' Guy | last post by:
How would I do this? public sealed class UtilityClass { public static MyObject Object1;//see note below about importance of static object names in this class public static MyObject Object2;...
3
by: John Haigh | last post by:
I have the need to create an array of objects. Now this sound fairly trivial but I can't figure this out. I have one class called PostingObjectService that has a method GetPostings where the...
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...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
2
by: Big Charles | last post by:
Hello, I would like to create an array-class to be able to call like: Dim oMyCar as New MyCar ' After initializing oMyCar, the object has to be like: oMyCar(0).Brand...
2
by: roadworrier | last post by:
I'm trying to create a new object to use as an associative array automatically. I can programmatically create new variables like this: for (var i; i < 10; i++) { window; window = "moo" +...
4
Ispep
by: Ispep | last post by:
Hi, unfortunately having a bit of difficulty with a question from an Open University course I'm currently doing. If you could help me out in any way I'd be grafeul (though obviously it goes without...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.