Java集合综述
来源:互联网 发布:淘宝卖孕婴用品怎么样 编辑:程序博客网 时间:2024/06/02 03:39
1. 集合类和数组
(1)数组元素可以是基本数据类型也可以是对象,而集合里只能保存对象。
(2)数组创建之后长度是固定的不能改变,集合类创建后长度可以随着数据量的大小自动增长。
2. Java集合接口由两个接口派生:Collection和Map。
3.Collection接口是List、Set、Queue接口的父接口,常用方法如下:
boolean
add(E e)
Ensures that this collection contains the specified element (optional operation).
boolean
addAll(Collection<? extendsE> c)
Adds all of the elements in the specified collection to this collection (optional operation).
void
clear()
Removes all of the elements from this collection (optional operation).
boolean
contains(Object o)
Returns true if this collection contains the specified element.
boolean
containsAll(Collection<?> c)
Returns true if this collection contains all of the elements in the specified collection.
boolean
equals(Object o)
Compares the specified object with this collection for equality.
int
hashCode()
Returns the hash code value for this collection.
boolean
isEmpty()
Returns true if this collection contains no elements.
Iterator<E>
iterator()
Returns an iterator over the elements in this collection.
boolean
remove(Object o)
Removes a single instance of the specified element from this collection, if it is present (optional operation).
boolean
removeAll(Collection<?> c)
Removes all of this collection's elements that are also contained in the specified collection (optional operation).
boolean
retainAll(Collection<?> c)
Retains only the elements in this collection that are contained in the specified collection (optional operation).
int
size()
Returns the number of elements in this collection.
Object[]
toArray()
Returns an array containing all of the elements in this collection.
<T> T[]
toArray(T[] a)
Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array
4.Collection遍历的两种方式:Iterator和foreachCollection<String> col = new HashSet<String>();col.add("a");col.add("b");col.add("c");col.add("d");//Iterator遍历Iterator it = col.iterator();while(it.hasNext()){System.out.print(it.next());}System.out.println();//foreach 遍历for(String str:col){System.out.print(str);}
0 0
- java 集合框架综述
- Java集合框架综述
- Java集合框架综述
- Java集合综述
- Java集合框架综述
- Java集合框架综述
- Java集合框架综述
- Java集合综述
- JAVA集合框架综述
- Java集合框架综述
- Java集合框架综述
- Java 集合框架综述
- java集合类案例综述
- Collection--Java中的collection(集合)接口综述
- java集合类(一)综述
- Java基础-集合框架1 综述
- java综述
- Java综述
- C内存对齐
- 2015 伦敦最美酒吧
- 【黑马程序员】C语言基础-C语言语法
- js正则表达式之$1$2$3$4$5$6$7$8$9属性,返回子匹配的结果
- northwind数据库导出为excel文件下载
- Java集合综述
- 学习笔记2:Struts2 +Spring JDBC
- JavaScript学习之路02_数据类型
- 从网络请求数据
- A + B Problem II
- 虚心使人进步富裕,骄傲使人落后贫困
- Linux软件安装包的命名规则
- C++中的lambda表达式详解
- 仿GMap.NET方式的Java版离线地图瓦片下载