This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I suppose one thing that might help me understand this is to know what classes are inherited when a String array (or any kind of array excluding ArrayLists) is created. I am positive that I have used some method (I don't remember it being the indexOf method) to find the index of an object within an array.
For some reason, when I try
I get an error saying "cannot find method indexOf"
If arrays inherit class Arrays, it HAS a method public int indexOf(Object o) since a string is an object..... (It also says the same thing if I cast it to an Object)
As I said, I remember doing this with another method......I just can't remember what that was... If I can get indexOf to work, that will be fine.
Every array is a direct subclass of Object. They inherit all the methods of Object and additionally have a static field "length". There is no method "indexOf(Object)" in Arrays. You seem to be thinking of a List, which is not at all the same thing as an array. There is a class called ArrayList which is an implementation of List that uses an array internally for a backing, but that does not in any way shape or form make it an array. You could accomplish this by converting it to a List: