Ive written these two methods but they are giving me lots of problems.
public int indexOf(Object element)
128 {
129 for(int i = 0; i < list.length; i++)
130 {
131 if(list[i] != null && list[i].equals(element))
132 {
133 return i;
134 }
135 }
136
137 throw new IndexOutOfBoundsException();
138 }
public boolean contains(Object element)
146 {
147 for(int i = 0; i < list.length; i++)
148 {
149 if(list[i] != null && list[i].equals(element))
150 {
151 return true;
152 }
153 }
154
155 return false;
156 }
157
This is what the code is supposed to do:
Contains:
Using the provided element's equals method, this method determines if the list contains the specified element or not. True if the list contains an element logically equal to the specified element, otherwise false.
indexOf:
Using the provided element's equals method, this method returns the index of the first element in the list that is equal to the provided element, if any. returns The index of the first matching element in the list.
Any help to fix these methods or rewrite them would be of great help. Ive been coding an extreme amount in the past 24 hours and im down to these two.