Wednesday, 11 September 2013

Remove an element from an array

Remove an element from an array

I need to remove an element of the array based on a match. Here is my
method to remove the event.
public boolean removeEvent(int year, int month, int day, int start, int
end, String activity)
{
Event newEvent = new Event(year, month, day, start, end, activity);
for (int i = 0; i < 5; i++)
{
if (newEvent.equals(events[i]))
{
events[i] = null;
newEvent = null;
numEvents--;
}
}
When I try
calendarTest1.removeEvent(2000, 1, 1, 1, 1, "Cal Test 1");
nothing happens. I have an element in my array with those values but it
does not change that element to null.
This is for homework so I don't really want to be told how to do it, just
why this does not work. Thank you.

No comments:

Post a Comment