JAVA集合学习笔记_千峰教育

集合大纲

image-20220407215351613

集合概念

image-20220407215601983

Collection体系集合

image-20220407215828301

Collection父接口

image-20220407215958035

Collection使用

add()/remove()

image-20220407220848194

迭代器Iterator工作过程

image-20220407221413231

这里的遍历不使用普通for循环是因为collection没有下标,因此无法使用

image-20220407221823177

image-20220407222044215

collection实际应用

image-20220407223226647

image-20220407223444011

image-20220407223822628

image-20220407224016606

image-20220407224048871

List子接口

image-20220407224502404

使用方法

image-20220409152809144

image-20220409152945722

image-20220409153355826

image-20220409153513227

image-20220409153920679

image-20220409154147342

List实现类

image-20220409154311789

image-20220409154433781

ArrayList使用

image-20220409155223559

image-20220409155520645

image-20220409155757292

image-20220409160518541

Vector类使用

image-20220409161341768

LinkedList类

  1. 添加元素

image-20220409161811983

  1. 删除元素

image-20220409161844494

  1. 遍历元素

image-20220409162037613

image-20220409162103845

  1. 判断、获取元素

image-20220409162141145

ArrayList与LinkedList区别

image-20220409162621318

Set子接口

image-20220409170351804

image-20220409170547240

使用方法

添加、删除数据

image-20220409171326401

遍历、判断数据

image-20220409171402049

Set实现类

HashSet()类

新建集合,添加、删除元素

image-20220409172143911

遍历、判断元素

image-20220409172216729

向HashSet集合中添加对象

  1. 创建对象类

image-20220409172429305

  1. 使用HashSet集合进行操作

image-20220409172821341

image-20220409173722176

image-20220409173902899

TreeSet()类

image-20220409195541528

创建集合,添加、删除元素

image-20220409200103766

遍历、判断元素

image-20220409200128628

TreeSet()复杂使用:

image-20220409200647847

实现Comparable接口步骤:
  1. 存储数据对象的类implement接口

image-20220409201822065
2. 重写接口中的compareTo()方法

image-20220409201706015
image-20220409202036071

字符串比较时,若相等则compareTo()方法返回值为0,不相等则为正负数

删除、遍历、判断元素

image-20220409202301255

Comparator比较器

image-20220409203355019

使用案例

image-20220409203644930

泛型

泛型简介

image-20220409162842231

泛型类

泛型类

这里的T只是占位符,也可用其它大写字母代替

image-20220409163613750
new泛型类对象时必须指明T的类型

image-20220409163512886

泛型接口

泛型接口

image-20220409164009714

泛型接口实现类

image-20220409164301315

image-20220409164815150

测试类

image-20220409164607412

泛型方法

泛型方法

image-20220409165037730

调用泛型方法

image-20220409165221180

泛型好处

image-20220409165309021

以这个图为例,若不使用泛型,show()方法仅能定义一种传入数据类型,因此就需要方法重载,写多个show()方法,而泛型只需要写一个,提高了代码复用性

泛型集合

image-20220409165736060

image-20220409170052177

迭代器

image-20220409170144562

image-20220409170231146

Map集合

体系结构

image-20220409203729006

特点

image-20220409203808027

Map父接口

常用方法

image-20220409203912145

Map接口使用

创建Map集合,添加、删除元素

image-20220409204447955

遍历元素

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fJmnP6KT-1649512258354)(https://gitee.com/caoyusuiyuexiangban/picture/raw/master/image/202204092051926.png)]

image-20220409205441566

判断元素

image-20220409205550294

Map集合的实现类

HashMap类

image-20220409205709284

image-20220409210108873

创建集合,添加元素

image-20220409210418285

删除、遍历、判断元素

image-20220409210921204

Hash table类

image-20220409211805347

Properties类(讲完流后再细讲)

image-20220410211226082

image-20220410211307087

具体使用
  1. 创建集合,添加数据,遍历数据

    image-20220410211712092

  2. list()方法:通过打印流将集合中内容打印如文件

    image-20220410212037119

  3. store()方法:保存

    image-20220410212719342

    store.properties : 保存properties集合数据的文件一般为properties类型

  4. load()方法:加载

    image-20220410212906908

TreeMap类

image-20220409212047480

实现Comparable接口
  1. 排序时使用的是Key值,因此Key值对象对应的类需implements接口

image-20220409212611610

  1. 重写compareTo()方法指定排序规则

image-20220409212704247

创建集合,添加元素

image-20220409212755592

删除、遍历元素

image-20220409212915616

判断元素

image-20220409213007239

Comparator定制比较器

image-20220409213116911

Collections工具类

image-20220409213218340

sort排序、binarySerch二分查找

image-20220409213556104

copy复制、reverse打乱

image-20220409214048883

补充:将集合转数组、数组转集合

image-20220409214653752

总结

image-20220409214729754

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值