Iterable 超级接口
这是一个老祖宗,一代一代往下拨
collection 的方法如下,是一个跟接口方法如下,见API
collection :
add():添加一个元素
addAll():添加一组元素
clear();清空
remove(Object o) :移除
removeAll():移除一组元素
isEmpty();判断集合中是否有元素,没有返回true
iterator():获得迭代器
size():返回集合长度

List
允许重复
存入顺序与取出顺序一致:有序
有序的
允许空值
允许重复的元素
get(int index):获得
set(int index, E element):修改
List下面已知的子类
ArrayList:单链表数据结构:查询速度,线程不同步
LinkedList
:双链表数据结构:插入与删除速度
Vector:线程同步
addFirst(E e)
addLast
removeFirst
removeLast
ArrayList取出数据的三种基本方法
import java.util.ArrayList;
import java.util.Iterator; public class ArraylistDemo {
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<Integer>();
list.add((int) 'e');
list.add(2);
list.add(3);
list.add(2);
list.add(null);
Iterator<Integer> i = list.iterator(); //迭代器迭代
while (i.hasNext()) {
Object s = i.next();
System.out.println(s);
}
for (int j = 0; j < list.size(); j++) { //for循环
System.out.println(list.get(j));
}
for (Integer integer : list) { //加强for循环
System.out.println(integer);
}
}
}
Vector
vector和ArrayList操作基本一样,Vector相当于ArrayList的旧版. Vector线程是安全的.在Vector下有一个枚举(Enumeration)的方法,和ArrayList下的迭代器(Iterator)功能一样
Set与Map见下节
Iterable 超级接口的更多相关文章
- JDK源码阅读(三) Collection<T>接口,Iterable<T>接口
package java.util; public interface Collection<E> extends Iterable<E> { //返回该集合中元素的数量 in ...
- Iterable<T>接口
https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html public interface Iterable<T> ...
- 12.Java中Comparable接口,Readable接口和Iterable接口
1.Comparable接口 说明:可比较(可排序的) 例子:按照MyClass的y属性进行生序排序 class MyClass implements Comparable<MyClass> ...
- Java之iterator迭代器和iterable接口
java.lang.Iterable java.util.Iterator Iterator是迭代器类,而Iterable是接口. 好多类都实现了Iterable接口,这样对象就可以调用iterato ...
- Iterator、Iterable接口的使用及详解
Java集合类库将集合的接口与实现分离.同样的接口,可以有不同的实现. Java集合类的基本接口是Collection接口.而Collection接口必须实现Iterator接口. 以下图表示集合框架 ...
- Collection<E>、Iterable<T>和Iterator<E>接口
Collection接口 public interface Collection<E>extends Iterable<E> Collection接口主要包含以下方法: Ite ...
- Java 集合-Collection接口和迭代器的实现
2017-10-30 00:30:48 Collection接口 Collection 层次结构 中的根接口.Collection 表示一组对象,这些对象也称为 collection 的元素.一些 c ...
- Java容器---Collection接口中的共有方法
1.Collection 接口 (1)Collection的超级接口是Iterable (2)Collection常用的子对象有:Map.List.Set.Queue. 右图中实现黑框的ArrayLi ...
- java中ExecutorService接口
一.声明 public interface ExecutorService extends Executor 位于java.util.concurrent包下 所有超级接口:Executor 所有已知 ...
随机推荐
- iOS中的UIWindow
UIWindow的作用 UIWindow主要有两个作用: 1 作为UIView视图的最顶层容器,包含所有要显示的UIView 2 传递触摸,非触摸,键盘事件,其中传递非触摸和键盘事件时,UIWindo ...
- Animation 案例解释
Animation 案例解释: ------------摘自W3c 过度动画类型: linear:线性过渡.等同于贝塞尔曲线(0.0, 0.0, 1.0, 1.0) ease:平滑过渡.等同于贝塞尔曲 ...
- MySQL查询指定时间的数据
user_event :用户事件表 create_time :表中存储时间的字段 #获取当月数据 SELECT * FROM user_event WHERE DATE_FORMAT(create_t ...
- JS 操作一个数据值
任何语言都有自己的操作数据的方法: Js也不例外,js有3种重要的方式来操作一个数据值. 1>复制它.例如把它赋给一个新的变量. 2>把它作为参数传递给一个函数或方法. 3>可以和其 ...
- matlab读取多幅图片,并对读取的图片降采样和双三次插值
clear all clc im = {}; %%创建字典im以保存读取的图片 dis = dir('C:\Users\KCl\Documents\MATLAB\SRCNN\Set5\*.bmp'); ...
- 红帽(Red Hat Linux)下SVN服务器的安装与配置
转:http://www.cnblogs.com/xd502djj/archive/2011/01/21/1941404.html 第一章 安装 1. 采用源文件编译安装.源文件共两个,为:subve ...
- LeetCode_Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...
- Linux企业级项目实践之网络爬虫(23)——系统测试:找出系统中的bug
为了验证爬虫的业务流程.性能和健壮性需要进行测试. 软件测试是描述一种用来促进鉴定软件的正确性.完整性.安全性和质量的过程.软件测试的经典定义是:在规定的条件下对程序进行操作,以发现程序错误,衡量软件 ...
- 【转】Win7系统下安装Ubuntu12.04(EasyBCD硬盘安装)--不错
原文网址:http://blog.csdn.net/lengbuleng1107/article/details/14532177 需要的东西有: 1,ubuntu系统镜像,下载地址:http://w ...
- Ugly Number II 解答
Question Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime ...