The difference between a list and a listing

I have a written method for getting all the entries and returning to the List Type, but I got an error from memory . Therefore, I changed the return type from List to Enumeration; instead of ArrayList in the method, it uses Vector and returns vector.elements at the end of the method. It works without errors. but I did not understand why.

Can anyone explain why this listing worked?

+4
source share
2 answers

You have to fix something. The vector will be used if there is something larger than the ArrayList memory, and returning Enumeration instead of the list itself adds only a little more memory usage unless your caller has used a list iterator, in which case it is a line score. Of course, there is no reason for this strategy to use significantly less memory.

If you have not returned a copy of the original list? how is the new ArrayList? This would double the memory usage at least as long as the copy was made, but it would be a very long list ...

0
source

Enumeration is an "old version" of Iterator .
Vector is the "old version" of ArrayList .

The difference in memory should not be significant, so perhaps the fluctuations that you observed are related to another.

Depending on the size of the list, you may need to increase the maximum JVM memory (using Xms , Xms and / or XX:MaxPermSize )

+5
source

Source: https://habr.com/ru/post/1306442/


All Articles