我是 Java 新手。
对于 Vectors,哪个更有效——clear() 或 removeAllElements()。我猜 removeAllElements 因为它保持容量不变(不释放内存)而 clear() 释放内存。根据应用的不同,两者都可能是理想的。
我会很感激一些意见。谢谢。
最佳答案
根据 JavaDoc关于 .removeAllElements() 方法。
"This method is identical in functionality to the clear method (which is part of the List interface)."
关于Java vector : clear vs removeAllElements method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5446383/