Quote (xcharliex @ May 23 2012 09:53pm)
I don't have a compiler on this computer and my disk space left is terrible, sorry :S I'd use the school computer's compiler but this is due first thing when I walk in the door so I don't really know how to get hold of a compiler by then. What would be the error displayed by the compiler if you don't mind showing me (assuming you have one)?
So the get method returns the element at the specified position in the list meaning that if I had an ArrayList where a[3] contained the integer 5 a call such as "a.get(3);" would return 5? And because of that would I wouldn't need to cast the returned object as an Integer because it is an integer as indicated in the header, but wouldn't I still need to instantiate the variable gh as an int? So it would start off as "int gh =" and then it would be followed by "a.get(22);"?
it would return the Integer object representing 5. however, that's the object type,
not the compile-time type. read the return type in the api.
public
E get(int index)
Imo your teacher failed when he used the word generic to describe how it was declared, since generics is a feature added to 1.5 and that does
not use generics.
So figure out what your E represents if you're not using generics, then ask yourself does the compiler know how to do that?
Quote
Also, would my new answer to #1 be correct?
I feel as though I'm over-complicating a lot of this

That would be my guess. however, i dont know off hand. ArrayList internally uses an array. but I don't know if that will put it into the 5th index internally when there are no other objects in there. I noticed your teacher did not use Generics either. In 1.5 java added autoboxing where it promotes primitives to object wrappers automatically. If your book is restricted to java 1.4, then you'll have to box it yourself
a.add(5, new Integer(x));
This post was edited by carteblanche on May 23 2012 08:12pm