什么是 List 与 ArrayList? [英] What is a List vs. an ArrayList?

查看:32
本文介绍了什么是 List 与 ArrayList?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两个对象的根本区别是什么?一个更有效率吗?有没有更多的方法?

What are the fundamental differences between the two objects? Is one more efficient? Does one have more methods?

推荐答案

List 在接口中,而 ArrayList 是一个类.

List is in interface while ArrayList is a class.

参见 ArrayList列表.

例如,您不能使用此设置:

E.g, you can't use this setup:

Listlist = new List();... 因为它是一个接口.

List<String> list = new List<String>();... Because it's an interface.

但是,这是有效的:

ArrayListarrayList = new ArrayList();

另外...你可以像下面duffymo所说的那样做,这或多或少与实现List接口(制作你自己的列表实现)相同.

Also... You can do as duffymo says below, which is more or less the same as implementing the List interface (making your own list implementation).

这篇关于什么是 List 与 ArrayList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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