草庐IT

Java vector : clear vs removeAllElements method

coder 2024-03-22 原文

我是 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/

有关Java vector : clear vs removeAllElements method的更多相关文章

随机推荐