请问ArrayList中减少的容量,当我们删除元素? [英] Does the capacity of ArrayList decrease when we remove elements?

查看:124
本文介绍了请问ArrayList中减少的容量,当我们删除元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ArrayList的有10个对象的默认容量。由于大小超过10个对象,一个ArrayList将在内部增加其容量。请问容量降低,当我们删除ArrayList中的对象。

ArrayList have a default capacity of 10 objects. As the size exceeds 10 objects, an ArrayList will internally increase its capacity. Does the capacity decrease when we remove the object from ArrayList.

如果ArrayList的容量不下降,这可能导致性能问题?

If the ArrayList capacity doesn't decrease, could this lead to performance issues?

推荐答案

它不会自动降低这一点。从文档。

It doesn't decrease this automatically. From the doc.

    public void trimToSize() 

修剪此ArrayList实例的容量是列表的当前大小。应用程序可以使用此操作来最小化ArrayList实例的存储。

Trims the capacity of this ArrayList instance to be the list's current size. An application can use this operation to minimize the storage of an ArrayList instance.

这篇关于请问ArrayList中减少的容量,当我们删除元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆