I tried the following simple
test.
The output of the above test is
I understand why the second line is producing 3 but i dont understand why the first line is not finding the new an object with title="Croydon".
The API describes the indexof method as one that
Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.
I think the API is saying that if the object is null then it will return the index of the first occurrence of a null object from the list. If it is not null it will return the index of the first occurrence where the passed in object equals method returns trued. Shouldnt the the object created as cities3.indexOf(new Cities("Croydon") equal to the object added previously as cities3.add(new Cities("Croydon")); ?
Thanks
[Edit - changed code tags to quote tags to fix the page width - MB]