473,322 Members | 1,409 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,322 software developers and data experts.

ArrayList Problems...

Hi, I'm trying to create an Arraylist Class which will allow me to output the whole list in one method. I think i've created the arraylist correctly but when i try to get the list to output i come across problems.
Here is my code,
Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2. import java.util.ArrayList.*;
  3.  
  4. public class People
  5. {
  6.  
  7.     public static void main (String[] args)
  8.     {
  9.         Person Chris = new Person("Chris", "Davies", 10, 7);
  10.         Person Jess = new Person ("Jess", "Levy", 4, 17);
  11.         Person Koo = new Person ("Tom", "McHowat", 4, 14);
  12.         Person Andy = new Person ("Andy", "Davies", 3, 6);
  13.  
  14.          ArrayList<Person> people = new ArrayList<Person>();
  15.         people.add(Chris);
  16.         people.add(Jess );
  17.         people.add(Koo );
  18.         people.add( Andy );
  19.  
  20.          int i = people.size();
  21.         Person allPeople = people.get(i-1);
  22.     }
  23.  
  24.     }
I've also tried to put the last two statements in a seperate method but the compiler can't find the variable people when i do this.

Any help would be much appreciated!
Thanks

Dave
Apr 29 '07 #1
2 1929
JosAH
11,448 Expert 8TB
I don't understand what you're doing in those last few statements: to me it
looks as you're getting the last Person from your "people" list; i.e. you're
not printing anything.

Hava you tried this?
Expand|Select|Wrap|Line Numbers
  1. System.out.println("people: "+people);
What does it print?

kind regards,

Jos
Apr 29 '07 #2
I don't understand what you're doing in those last few statements: to me it
looks as you're getting the last Person from your "people" list; i.e. you're
not printing anything.

Hava you tried this?
Expand|Select|Wrap|Line Numbers
  1. System.out.println("people: "+people);
What does it print?

kind regards,

Jos
Hi, Thanks again!

I wasn't sure what i was trying but found some information on the web and realised i was calling the people list rather than my person class. I've now changed it and it will allow me to print any of my methods from the person class! I've eventually got it!

Thanks for your help

Dave
Apr 29 '07 #3

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

Similar topics

7
by: Jerry S | last post by:
Hi I've got an arraylist of integers. I want to be able to remove an integer from the list using a method like this: public void ArrayListRemove(int indexnum) {...
10
by: Eric | last post by:
I'm looking at this page in the MSDN right here: ms-help://MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemcollectionsarraylist classsynchronizedtopic2.htm (or online here:...
9
by: vbportal | last post by:
Hi, I would like to add BitArrays to an ArrayList and then remove any duplicates - can someone please help me forward. I seem to have (at leaset ;-) )2 problems/lack of understanding (see test...
20
by: Dennis | last post by:
I use the following code for a strongly typed arraylist and it works great. However, I was wondering if this is the proper way to do it. I realize that if I want to implement sorting of the...
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
0
by: Grant Wickman | last post by:
Our team has just fixed a really nasty problem that appears to be caused by an obscure bug in the sort method of Arraylist and daisy-chained webservice stubs. We've fixed the bug so I'll not...
3
by: Stuart | last post by:
I am using Visual Basic 2005. I have created a two dimensional ArrayList named aSystem that is populated as follows:- aSystem.Add(New PickList(0, "Undefined")) aSystem.Add(New PickList(-1,...
6
by: fniles | last post by:
I am using VB.NET 2003 and a socket control to receive and sending data to clients. As I receive data in 1 thread, I put it into an arraylist, and then I remove the data from arraylist and send it...
3
by: carlos123 | last post by:
Ok, im having EXTREME problems, with arraylists, i simply dont understand them, yes i have read your article. Would someone just take a look at this code, i know it sucks. Look at the areas that say...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.