Java系列学习(十四)-集合
1.java中的集合学习
2.Collection中常用方法
1.添加功能
boolean add(E e):添加一个元素
boolean addAll(Collection<? extends E> c):添加一个集合
2.删除功能
void clear():移除所有元素
boolean remove(Object o):移除一个指定元素
boolean removeAll(Collection<?> c):移除指定集合中的元素【只要有元素被移除,就返回true】
3.判断功能
boolean contains(Object o):判断集合中是否包含指定元素
boolean containsAll(Collection<?> c):判断集合中是否包含指定集合元素【只有全部包含,才返回true】
boolean isEmpty():判断集合是否为空
boolean equals(Object o)
4.获取功能
Iterator<E> iterator():【父类中继承的方法】
int hashCode():返回集合的哈希值
5.长度功能
int size():获取集合中元素的个数
6.交集功能
boolean retainAll(Collection<?> c):两个集合的交集【A对B做交集,结果保存在A中;只有A不变,才返回true】
7.把集合转换成数组
Object[] toArray():把集合转换成数组,可实现集合的遍历
<T> T[] toArray(T[] a):
3.List特有的方法
1.添加功能
void add(int index, E element):在指定位置添加元素
boolean addAll(int index, Collection<? extends E> c):在指定位置添加集合
2.获取功能
E get(int index):获取指定位置的元素【与size()结合可实现遍历】
List<E> subList(int fromIndex, int toIndex)
int indexOf(Object o)
int lastIndexOf(Object o)
3.列表迭代器
ListIterator<E> listIterator():List集合特有的迭代器
ListIterator<E> listIterator(int index)
4.删除功能
E remove(int index):根据索引删除元素,返回被删除的元素
5.修改功能
4.Vector特有的功能
1.添加功能
public void addElement(E obj)
public void insertElementAt(E obj, int index)
2.获取功能
public E elementAt(int index)
public Enumeration<E> elements()
public int capacity():获取集合的容量
public int indexOf(Object o, int index)
public int lastIndexOf(Object o, int index)
public E firstElement():获取集合第一个元素
public E lastElement():获取集合最后一个元素
3.复制功能
public void copyInto(Object[] anArray)
4.修改功能
public void ensureCapacity(int minCapacity):增加集合的容量
public void setElementAt(E obj, int index)
public void trimToSize():使集合等于当前大小
public void setSize(int newSize):设置集合的大小
5.移除功能
public void removeAllElements():移除所有元素,并大小设置为零
public boolean removeElement(Object obj):移除第一个元素
public void removeElementAt(int index):移除指定元素
protected void removeRange(int fromIndex, int toIndex):移除指定范围元素【包括fromindex,不包括toIndex】
6.格式化功能
public String toString():返回集合的字符串形式【看源码,重写了】
LinkedList特有的方法:(可实现自定义栈)
public class LinkedList<E>extends AbstractSequentialList<E> implements List<E>, Deque<E>, Cloneable, Serializable
1.添加功能
public void addFirst(E e)
public void addLast(E e)
2.获取功能 3.public E getLast()
4public E getLast()
3.删除功能
public E removeFirst()
public E removeLast()
Java系列学习(十四)-集合的更多相关文章
- “全栈2019”Java第九十四章:局部内部类详解
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...
- “全栈2019”Java第十四章:二进制、八进制、十六进制
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...
- “全栈2019”Java第二十四章:流程控制语句中决策语句switch下篇
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...
- Java从零开始学二十四(集合工具类Collections)
一.Collections简介 在集合的应用开发中,集合的若干接口和若干个子类是最最常使用的,但是在JDK中提供了一种集合操作的工具类 —— Collections,可以直接通过此类方便的操作集合 二 ...
- Java笔记(二十四)……集合工具类Collections&Arrays
Collections 集合框架的工具类,方法全部为静态 Collections与Collection的区别 Collection是集合框架的一个顶层接口,里面定义了单列集合的共性方法 Collect ...
- 学JAVA第二十四天,Set集合与StringBuilder
下面的内容需要慢慢看,因为,我的语言表达能力不是很好 首先说Set把,Set集合是一个无序且不允许重复的集合,而且查找效率也是快的可怕的. 但是,有些时候,我们必须要用储存多个相同的值时,Set也是可 ...
- Java第十四天,集合、迭代器的使用
集合 集合框架 一.Collection 1.定义方法: Collection<E> obj = new Collection子类<>(); 因为Collection是一个抽象 ...
- 菜鸟学Java(十四)——Java反射机制(一)
说到反射,相信有过编程经验的人都不会陌生.反射机制让Java变得更加的灵活.反射机制在Java的众多特性中是非常重要的一个.下面就让我们一点一点了解它是怎么一回事. 什么是反射 在运行状态中,对于任意 ...
- Java Web(十四) 编写MyBookStore项目的总结
这几天一直没有发博文,原因是在写一个书城的小项目,作为web学习的最后沉淀,接下来就要到框架的学习了. --WH 一.项目介绍 从网上找的一个培训机构的小项目,名称叫做 书城购物网站 吧,其中就是分前 ...
随机推荐
- MySQL 乐观锁和悲观锁
前言 1)在数据库的锁机制中介绍过,数据库管理系统(DBMS)中的并发控制的任务是确保在多个事务同时存取数据库中同一数据时不破坏事务的隔离性和一致性以及数据库的一致性. 2)加锁是为了解决更新丢失问题 ...
- 升级 HTTPS,价值何在?
HTTPS 实质上是一种面向安全信息通信的协议.从最终的数据解析的角度上看,HTTPS 与 HTTP 没有本质上的区别.对于接收端而言,SSL/TSL 将接收的数据包解密,将数据传给 HTTP 协议层 ...
- Tensorflow Eager execution and interface
Lecture note 4: Eager execution and interface Eager execution Eager execution is (1) a NumPy-like li ...
- [luoguP1130] 红牌(DP)
传送门 幼儿园DP. ——代码 #include <cstdio> #include <iostream> ; << ); int a[MAXN][MAXN], f ...
- jquery ajax获取json并解析,获取的json是object对象格式
首先我们使用的是ajax方式,推荐一个学习网址: http://blog.csdn.net/shiyaru1314/article/details/51065410 这个博主写的特别好.现在来看我们的 ...
- PatentTips - Method for booting a host device from an MMC/SD device
FIELD OF THE INVENTION The present invention relates to a memory device and especially to the interf ...
- 20181012关于mysql内部执行流程
转自:https://www.cnblogs.com/annsshadow/p/5037667.html 步步深入:MySQL架构总览->查询执行流程->SQL解析顺序 前言: 一直是 ...
- E - Super Jumping! Jumping! Jumping! DP
Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. May ...
- 最小生成树+BFS J - Borg Maze
The Borg is an immensely powerful race of enhanced humanoids from the delta quadrant of the galaxy. ...
- NetCore +EFCore+SqlServer根据数据库生成实体类到项目中
转载自:https://www.cnblogs.com/yangjinwang/p/9516988.html 1.点击“工具”->“NuGet包管理器”->“程序包管理器控制台” 分别安装 ...