I have a written a method to get all the records and return in the List Type,
but I got out of memory error.
So I changed return type from List to Enumeration, in the method, instead of ArrayList, uses Vector and return vector.elements at the end of the method.
It works without any error. but I did not understand why.
Could someone explain Why this Enumeration worked?
You must have fixed something else. A Vector will use if anything more memory than an ArrayList, and returning an Enumeration instead of the list itself only adds a tiny bit more memory usage, unless your caller was using a list iterator in which case it is line ball. There’s certainly no reason for this strategy to use significantly less memory.
Unless you were returning a copy of the original list? as a new ArrayList? That would double the memory usage at least while the copy was being made, but it would have to be a very long list …