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 所有已知 ...
随机推荐
- QT小技巧学习记录
1. 光标定位最后一行 ui->revTextBrower->moveCursor(QTextCursor::End); 2. 隐藏标题栏3. 如果不考虑跨平台的话,在隐藏标题栏的 ...
- OSG多屏显示问题
// testMultiScreen.cpp : Defines the entry point for the console application.// #include "stdaf ...
- 利用System.Net.Mail和多线程实现邮件发送
对于邮件发送,一般来说,程序会响应超过1秒,这样对于用户体验来说,让用户等待的时间过长,而且发送的邮件越多时间就越长,所以这里我利用了线程的来处理邮件发送这种耗时的工作,废话不多说,直接上代码 pri ...
- ShopEx访问提示Incompatible file format: The encoded file has format major ID 2, whereas the Loader expects 4
今天测试了下ShopEx程序,但是ShopEx安装时(程序放在public_html目录下的test目录中)遇到了问题,提示错误如下:Fatal error: Incompatible file fo ...
- Grunt使用心得
1.安装npm 2.安装CLI ( npm install -g grunt-cli) 3.安装grunt (npm install grunt --save-dev) 4.添加gruntfile.j ...
- 使用laravel的任务调度(定时执行任务)
laravel中有一个很强大上的功能,只需要在服务器上添加一个cron条目,就可以定时执行所有的laravel任务. 现在有如下数据表: 我想让cron表中的cron字段的值每分钟增加1,那么我需要如 ...
- c++中的迭代器 iterator
迭代器iterator的作用类似于指针. iterator只有针对制定<类型>的容器才有效.例如: vector<int> vec; vector<int>::it ...
- 从现在开始使用nodejs开发的几点答疑
1.为什么要开始用nodejs, 而不是php 理由有三点: 因为我是前端程序员出身,nodejs都是用javascript写的,这样相当于前端和后端都使用javascript,开发更加有效率.当然很 ...
- 如何应对“改变现状”的失败"
参加工作后,利用闲暇时间看了一些书,发现以上的场景可以通过心理学,神经生物学等相关的知识来解析,同时也可以利用这些知识来进行一些改进.那么下文就来尝试通过心理学来解析这个场景,同时提出一些改进方法. ...
- HDU4821---字符串hash,map判重
这是2013年长春区域赛的铜牌题...然而第一次做的时候一直觉得会超时的..最后才知道并没有想象中的那么恐怖: 这题有两个注意的地方: (1)h[i] = h[i-1] * seed + s[i] - ...