Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Passsing Data into an array one at atime

Hi, I need help parameters one at a time into array when an object is made. I want data to be added to the array as the objects are created.Im passing parameters in from TestBook to BookFile.All help will be much apprieciated!
[226 byte] By [kenod] at [2007-11-11 7:19:02]
# 1 Re: Passsing Data into an array one at atime
In your code in the BookFile class, you are calling bookFile = new BookFile[20]; in the constructor. You will lose all the previous records with that statement.

To add a new record to the array, you need to loop over the existing array and add a record to a position where the reference is not null and the title is not already present. Anyway, I think your array should hold Book objects rather than BookFile objects. I also think you are not achieving anything by making the BookFile class extend the Book class.
aniseed at 2007-11-11 22:38:47 >
# 2 Re: Passsing Data into an array one at atime
In my opinion, your problem could be solved easily with an ArrayList.
aniseed at 2007-11-11 22:39:42 >
# 3 Re: Passsing Data into an array one at atime
Another problem I observed in the BookFile class,
title.equals(bookFile[i])

This will always be false since title is a String and bookFile is a BookFile object.

As per the API, the equals() method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.
aniseed at 2007-11-11 22:40:51 >