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

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

问题描述

什么是两个物体之间的根本区别是什么?一个更有效率?做一件有更多的方法呢?

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

推荐答案

列表是接口,而ArrayList是一个类。

List is in interface while ArrayList is a class.

请参阅的ArrayList 和<一个HREF =htt​​ps://docs.oracle.com/javase/8/docs/api/java/util/List.html相对=nofollow>列表。

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

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

列表&LT;串GT;名单=新名单,LT;弦乐&GT;(); ...因为它是一个接口

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

不过,这个作品:

的ArrayList&LT;串GT; ArrayList的=新的ArrayList&LT;串GT;();

另外...你可以做duffymo下面说,这是或多或少一样实施列表界面(制作自己的列表实现)。

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).

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

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