First of all i have little experience in Java.
Getting to my question, I am implementing my own list with my own methods.
public class MyList<E> implements List<E>{
.....
One of this methods returns the size of my list
public int getSize(){
....
}
Then I have two other methods that would be more simple if I could somehow apply this method to my list. How so?
I have a method that has to compare if a given list is equal to this list
public boolean equals(Lista<E> list){
....
}
I had though about first comparing the size of both list, and if they don't match it returns false. if they do, it continues to compare each element. Is this possible? How would I applied getSize ? If this is not possible, i will just compare element by element.
My other method has to return an array of each element
public Object[] toArray() {
E myarray = new E[??]
As you can see, i dont' know how to declare this array. I would have to know beforehand the size of my list. I though about passing as an argument (which would solve the problem) but i need to solve it this way.