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 所有已知 ...
随机推荐
- c笔试题(1)
1.sizeof和strlen的区别 #include<stdio.h> #include<string.h> int main() { char a[10] = " ...
- 使用laravel的任务调度(定时执行任务)
laravel中有一个很强大上的功能,只需要在服务器上添加一个cron条目,就可以定时执行所有的laravel任务. 现在有如下数据表: 我想让cron表中的cron字段的值每分钟增加1,那么我需要如 ...
- 在预装win8的电脑上换win7系统讲解
现在买电脑,如果电脑预装的系统是win8系统,那么这个电脑的默认启动模式应该就是UEFI模式,现在UEFI模式正在逐渐取代传统模式.UEFI启动需要一个独立的分区,它将系统启动文件和操作系统本身隔离, ...
- OC 冒泡排序 -- 核心代码
//冒泡 核心代码 for (int i = 0; i < array.count - 1; i++) { int a = [array[i] intValue]; for (int j = i ...
- proxifier 注册码
https://www.proxifier.com/index.htm L6Z8A-XY2J4-BTZ3P-ZZ7DF-A2Q9C(Portable Edition) 5EZ8G-C3WL5-B56Y ...
- 基于toyix的进程和轻权进程的学习
我们在平时的计算机课上学习过进程,知道程序的执行的背后其实就是进程在进行一些操作.大家都知道打开windows的任务管理器可以看到正在运行的进程,当程序卡死时,可以在任务管理器里强制关闭相关程序的进程 ...
- eclipse kepler 创建 maven web 项目
1. 创建一个maven project 注意 :不勾选 create a simple project 选项.点击next 2. 下一步后,在filter 中输入webapp,选中 maven- ...
- Unity 3D中的菜单项
1.File菜单:主要是包含项目和场景的创建.保存以及输出等功能.2.Edit(编辑)菜单:只要包括对场景进行一系列的编辑以及环境设置操作等命令.3.Assets(资源)菜单:掌握资源在Unity中的 ...
- KEIL 伪指令
//为了大家查找方便,命令按字母排序:0.ALTNAME 功能: 这一伪指令用来自定义名字,以替换源程序中原来的保留字,替换的保留字均可等效地用于子程序中. 格式: ALTNAME 保留字 自定义名 ...
- 编译Qt 4.7.3的时候发生NMAKE : fatal error U1077: 'cd' : return code '0x2'
怀疑是configure的时候没加-nomake demos -nomake examples的问题 references: http://stackoverflow.com/questions/10 ...