关系

List 是 Java Interface, ArrayList 是 Java Class,它们都属于 java.util 包。

Java List 是有序的集合(ordered collection),也称为序列(Sequence);

Java ArrayList 是 Java List Interface 的可变大小的数组实现。

这两者在 JAVA collection framework 位置,如下图所示:

再来看看官方文档说明:

java.util

Interface List<E>

  • Type Parameters:

E - the type of elements in this list

All Superinterfaces:

Collection<E>, Iterable<E>

All Known Implementing Classes:

AbstractListAbstractSequentialListArrayListAttributeListCopyOnWriteArrayListLinkedListRoleListRoleUnresolvedListStackVector


public interface List<E>

extends Collection<E>

An ordered collection (also known as a sequence).

java.util

Class ArrayList<E>

All Implemented Interfaces:

SerializableCloneableIterable<E>, Collection<E>, List<E>, RandomAccess

Direct Known Subclasses:

AttributeListRoleListRoleUnresolvedList


public class ArrayList<E>

extends AbstractList<E>

implements List<E>, RandomAccess, Cloneable, Serializable

Resizable-array implementation of the List interface.

示例

1. 新建一个 ArrayList 对象

List<String> brands = new ArrayList<String>();

2. 向其中增加元素

brands.add("Jack Amber");

3. 完整示例

// BeerExpert.java, excerpted from Dawn Griffiths & David Griffiths, "Head First Android Development",  2015
import java.util.ArrayList;
import java.util.List; public class BeerExpert {
List<String> getBrands (String color) {
List<String> brands = new ArrayList<String>();
if (color.equals("amber")) {
brands.add("Jack Amber");
brands.add("Red Moose");
} else {
brands.add("Jail Pale Ale");
brands.add("Gout Stout");
} return brands;
}
}

参考资料

[1] Oracle Corporation. Class ArrayList<E> - Java™ Platform Standard Ed. 8 [OL]. https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html

[2] Oracle Corporation. Interface List<E> - Java™ Platform Standard Ed. 8 [OL]. https://docs.oracle.com/javase/8/docs/api/java/util/List.html

[3] Stack Overflow Users. Type List vs type ArrayList in Java [OL]. https://stackoverflow.com/questions/2279030/type-list-vs-type-arraylist-in-java

最新文章

  1. 如何给不支持新特性的浏览器打补丁(让老版本IE兼容新特性)
  2. ASP.NET MVC请求处理管道生命周期的19个关键环节(1-6)
  3. Spring Boot工程发布到Docker
  4. 《ASP.NET1200例》当前上下文中不存在名称configurationmanager
  5. android 单独编译某个模块
  6. SQL Server 127个SQL server热门资料汇总
  7. word-wrap同word-break的区别(转)
  8. java学习面向对象之多态
  9. 统计单词频率--map
  10. html 压缩工具 html-minifier
  11. Shiro第四篇【Shiro与Spring整合、快速入门、Shiro过滤器、登陆认证】
  12. python迭代和切片
  13. socket通信如何处理每次包长度不定问题
  14. vue实战记录(二)- vue实现购物车功能之创建vue实例
  15. mongodb集群配置副本集
  16. scala学习——(1)scala基础(上)
  17. cocos2d-x 真正的定时器之schedule
  18. linux下yum命令出现Loaded plugins: fastestmirror Determining fastest mirrors
  19. RocketMQ 2主2从 集群搭建
  20. 批量读取文件matlab

热门文章

  1. Python中使用PyMySQL
  2. yield return 的使用方法
  3. HBase启动时IP地址解析不正确的问题及解决方法
  4. Linux Intro - Remove 302 字符
  5. 008-PageBean类模板
  6. Java线程问题(基础回顾)
  7. AOP的最佳注入方式——MSIL注入
  8. 游戏场景下的DDoS风险分析及防护
  9. Mybatis缓存(一)
  10. Java中子类覆盖父类方法所必须满足的条件