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接口的意义是为各种具体的集合提供了最大化 的统一操作方式,其直接继承接口 ...
随机推荐
- vue生成路由实例, 使用单个vue文件模板生成路由
一.vue-loader与vue-router配合 $ cnpm install vue-router --save 二.生成vue-webpack模板 $ vue init webpack-simp ...
- thinkphp自动验证详解
自动验证时THINKPHP提供的一种比较好的验证方式,可以在使用create创建数据对象的时候自动进行数据验证. 数据进行自动验证的方式有两种: 1.静态方式:在模型类里面通过$_validate属性 ...
- 近期在看的一段JS(谁能看出我想实现什么功能)
示例代码: <script type="text/javascript"> !function(){ var e=/([http|https]:\/\/[a-zA-Z0 ...
- 有向图的强联通tarjan算法(判断是否为强联通模板)(hdu1269)
hdu1269 迷宫城堡 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- 04 用户个人信息和二次开发django的文件存储系统
用户的个人信息的前端页面如下: 业务逻辑分析 从上图中可以看出,需要后端传送的数据有,用户的名字和练习的地址,和最近的浏览记录. 用户的名字和联系的地址可以通过地址表(adress)中获得,地址表可以 ...
- vue报错 Module not found: Error: Cannot resolve 'file' or 'directory'
炸了,我好写sell而组件,直接就用了,我的天哪 看你的写了吗,就用: Module not found: Error: Cannot resolve 'file' or 'directory' 页另 ...
- confirm
注意confirm是window对象的方法,当确认时,返回true,取消时,返回false
- CodeForces 551C - GukiZ hates Boxes - [二分+贪心]
题目链接:http://codeforces.com/problemset/problem/551/C time limit per test 2 seconds memory limit per t ...
- Ubuntu:Android编译环境设置和编译
1. 设置 Android 4.4 编译环境 1.删除 Java 7 sudo apt-get remove openjdk-7-jdk sudo apt-get remove openjdk-7-j ...
- 四种数据库随机获取N条数据的方法
1.SQL Server: SELECT TOP n * FROM tableName ORDER BY NEWID(); 2.ORACLE: SELECT * FROM (SELECT * ...