Summary: Arrays vs. Collections && The differences between Collection Interface and Collections Class
Java offers two types of constructs where you can store multiple values or objects of the same type: arrays and collections (for System Dynamics models AnyLogic also offers HyperArray, also known as "subscripts", – a special type of collection for dynamic variables).
Array or collection? Arrays are simple constructs with linear storage of fixed size and therefore they can only store a given number of elements. Arrays are built into the core of Java language and the array-related Java syntax is very easy and straightforward, for example the nth element of the array can be obtained as array[n]. Collections are more sophisticated and flexible. First of all, they are resizable: you can add any number of elements to a collection. A collection will automatically handle deletion of an element from any position. There are several types of collections with different internal storage structure (linear, list, hash set, tree, etc.) and you can choose a collection type best matching your problem so that your most frequent operations will be convenient and efficient. Collections are Java classes and syntax for obtaining, e.g., the nth element of acollection of type ArrayList is collection.get(n).

From a capability perspective, while both can store references to objects:
- Arrays can store primitives
- Collections can not store primitives (although they can store the primitive wrapper classes, such as
Integeretc)
One important difference, commonly not understood by programmers new to java, is one of usability and convenience, especially given that Collections automatically expand in size when needed.
Collection, as its javadoc says is "The root interface in the collection hierarchy." This means that every single class implementing Collection in any form is part of the Java Collections Framework.
The Collections Framework is Java's native implementation of data structure classes (with implementation specific properties) which represent a group of objects which are somehow related to each other and thus can be called a collection.
Collections is merely an utility method class for doing certain operations, for example adding thread safety to your ArrayList instance by doing this:
List<MyObj> list = Collections.synchronizedList(new Arraylist<MyObj>());
The main difference in my opinion is that Collection is base interface which you may use in your code as a type for object (although I wouldn't directly recommend that) while Collections just provides useful operations for handling the collections.
Summary: Arrays vs. Collections && The differences between Collection Interface and Collections Class的更多相关文章
- 【转载】#445 - Differences Between an Interface and an Abstract Class
An interface provides a list of members, without an implementation, that a class can choose to imple ...
- Java精选笔记_集合概述(Collection接口、Collections工具类、Arrays工具类)
集合概述 集合有时又称为容器,简单地说,它是一个对象,能将具有相同性质的多个元素汇聚成一个整体.集合被用于存储.获取.操纵和传输聚合的数据. 使用集合的技巧 看到Array就是数组结构,有角标,查询速 ...
- Collection接口和Collections类的简单区别和讲解
这里仅仅进行一些简单的比较,如果你想要更加详细的信息话,请自己百度. 1.Collection: 是集合类的上层接口.本身是一个Interface,里面包含了一些集合的基本操作. Collection ...
- postman接口测试之复制多个接口或collections到某个子文件夹或collections下
一.痛点 1.postman只支持复制一个请求,或者一个子文件夹,但是不支持复制多个请求,或者整个collections到某个子文件夹或者某个collections下. 2.网上查了好一会儿,没有一个 ...
- [19/03/27-星期三] 容器_Iterator(迭代器)之遍历容器元素(List/Set/Map)&Collections工具类
一.概念 迭代器为我们提供了统一的遍历容器的方式 /* *迭代器遍历 * */ package cn.sxt.collection; import java.security.KeyStore.Ent ...
- NET设计规范(二) 命名规范
http://blog.csdn.net/richnaly/article/details/6280294 第2章 命名规范 2.1. 大小写约定 2.1.1. 标识符的大小写规 ...
- 程序猿的量化交易之路(32)--Cointrade之Portfolio组合(19)
转载须注明出处:http://blog.csdn.net/minimicall?viewmode=contents,http://cloudtrade.top/ Portfolio:组合,代表的是多个 ...
- Collection 和 Collections;Array与Arrays的区别
Collection 和 Collections 的区别. Collection 是个 java.util 下的接口 ,它是各种集合结构的父接口.继承与他的接口主要有 Set 和 List. Col ...
- Java集合(三)--Collection、Collections和Arrays
Collection: Collection是集合类的顶级接口,提供了对集合对象进行基本操作的通用接口方法.Collection接口的意义是为各种具体的集合提供了最大化 的统一操作方式,其直接继承接口 ...
随机推荐
- POP3协议分析
http://m.blog.csdn.net/bripengandre/article/details/2192111 POP3协议分析 第1章. POP3概述 POP3全称为Post Off ...
- Oracle 12C 创建用户连接pdb
测试环境: C:\ora12c\product\12.1.0\dbhome_1\BIN>sqlplus.exe /nolog SQL*Plus: Release 12.1.0.1.0 Produ ...
- IIS6配置后仍然无法解析json文件解决办法
两台服务器,都是Windows Server2003,照着以下办法设置后,一台可以访问到json文件,一台不可以. 1. MIME设置: 在IIS的站点属性的HTTP头设置里,选MIME 映射中点击” ...
- Kerberos认证与攻击学习总结
0.背景 聆听了n1nty大佬(90后黑客代表)的谆谆指导,学习了n1nty大佬的基本操作,决定总结一下,做一个简要的读书笔记,也把之前自己记录的关于Windows的安全的一些博客能够串联起来.所以首 ...
- 利用Jenkins未授权获取服务器权限--Docker还来干扰--一次渗透的经历
Jenkins获取权限的过程 Jenkins存在未授权访问漏洞 Jenkins存在未授权访问漏洞,且项目具有读取权限,通过项目的日志获取到一个账号密码,尝试登录成功,打开控制台成功. 备注:控制台一般 ...
- github命令行下载项目源码
一.git clone [URL] 下载指定ur的源码 $ git clone https://github.com/jquery/jquery 二.指定参数, -b是分支, --depth 1 最新 ...
- C# 未能加载文件或程序集“mysql.data”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)
报错信息: 在web.config中已经加了以下代码. <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-co ...
- python的接口和抽象类
抽象基类 有些面向对象的语言,如JAVA,支持接口,可以声明一个支持给定的一些方法方法,或者支持给定存取协议的类.抽象基类(或者ABCs)是Python里一个相同的特性.抽象基类由abc模块构成,包含 ...
- Vim多行编辑
vim编辑文档有时候需要多行同时插入或者删除,比如多行加注释应该怎么操作 vim进了多行编辑模式:<ESC>之后按CTRL+V进入visual block模式(列编辑). 光标移到某行行首 ...
- PAT甲1101 Quick Sort
1101 Quick Sort (25 分) There is a classical process named partition in the famous quick sort algorit ...