new commit

This commit is contained in:
icecat
2026-01-07 16:14:38 +08:00
parent e2d599debe
commit ccf7b50b0d
137 changed files with 1771 additions and 0 deletions

View File

@@ -76,9 +76,28 @@ public class Test2 {
## List集合的5种遍历方式
1. Iterator迭代器
<img src="https://gitee.com/icecat2233/picture/raw/master/20251221153337614.png" alt="image-20251221153329358" style="zoom:50%;" />
2. 增强for循环
```Java
//增强for循环
//for(元素类型,起名 : 遍历的集合)
for (Student stu : c) {
System.out.println(stu);
}
```
3. foreach
```Java
//foreach循环
c.forEach(stu -> System.out.println(stu));
```
4. 普通for循环
5. ListIterator迭代器
# 数据结构:栈 队列 链表 数组
@@ -102,3 +121,187 @@ public class Test2 {
## LinkedList特有方法
removeFirst() removeLast()
# Set集合
<img src="https://gitee.com/icecat2233/picture/raw/master/20251220175508010.png" alt="image-20251220175506487" style="zoom:67%;" />
## 数据结构:树
树的知识点总结:
![image-20251012170947546](https://gitee.com/icecat2233/picture/raw/master/20251012171010346.png)
## 三种二叉树
![image-20250509183934916](https://gitee.com/icecat2233/picture/raw/master/20250509183936223.png)
## 平衡二叉树
<img src="https://gitee.com/icecat2233/picture/raw/master/20250509183513481.png" alt="image-20250509183446340" style="zoom: 50%;" />
## 红黑树(重难点)
红黑树是一种特殊的平衡二叉树,但并不是完全平衡的平衡二叉树,效率最高
**添加树的情况**
![image-20250509201524220](https://gitee.com/icecat2233/picture/raw/master/20250509201525478.png)
## TreeSet集合
**排序和取出顺序示例:**
![image-20251217162402752](https://gitee.com/icecat2233/picture/raw/master/20251217162411298.png)
**自然排序示例:**
![image-20250510170405367](https://gitee.com/icecat2233/picture/raw/master/20250510170406417.png)
比较器排序示例:
### **注意:**
**this - 0 正序 o-this 降序**
**o1 - o2 正序o2 - o1 降序**
<img src="https://gitee.com/icecat2233/picture/raw/master/20250510170601190.png" alt="image-20250510170600150" style="zoom: 67%;" />
<img src="https://gitee.com/icecat2233/picture/raw/master/20250510170515008.png" alt="image-20250510170513793" style="zoom:50%;" />
两种方式比较:
<img src="https://gitee.com/icecat2233/picture/raw/master/20250510170101423.png" alt="image-20250510170052265" style="zoom:67%;" />
# HashSet
## 基本运用:
特点去重hashCode方法和equals方法共同运用
遍历迭代器增强for循环foreach方法
## **HashSet组成**
<img src="https://gitee.com/icecat2233/picture/raw/master/20251220165008373.png" alt="image-20251220165000000" style="zoom:67%;" />
## **JDK8版本以后Hashset的添加过程面试常问重点**
### **2**步骤过程:
**将数值调用hashCode方法得到原始哈希值然后将原始哈希值向右移动16位与原始哈希值进行异或操作得到的数值与数组长度作取模运算得到位置。**
<img src="https://gitee.com/icecat2233/picture/raw/master/20251220165204636.png" alt="image-20251220165202216" style="zoom:67%;" />
## 如何提高HashSet查询过程
<img src="https://gitee.com/icecat2233/picture/raw/master/20251220165544826.png" alt="image-20251220165543271" style="zoom:67%;" />
## LinkedHashSet集合
## 特点:
**有序**,不重复,无索引,保证存取顺序。
# 集合总结:
![image-20251220171433114](https://gitee.com/icecat2233/picture/raw/master/20251220171435072.png)
# 小知识点:可变参数
可变参数用在形参中可以接受多个数据。
例:`int... 名称`
传输参数非常灵活方便可以不传参数可以传1个或多个也可以传数组
**方法本质就是一个数组**
# Collections集合工具类
![image-20251220173953237](https://gitee.com/icecat2233/picture/raw/master/20251220173954809.png)
![image-20251220174214148](https://gitee.com/icecat2233/picture/raw/master/20251220174215755.png)
示例:
```java
//多数据添加
TreeSet<Student> alist = new TreeSet<>();
Collections.addAll(alist,new Student("张三",14),new Student("八奈见杏菜",16),new Student("七奈见杏菜",16));
System.out.println(alist);
//二分查找
ArrayList<String> ts = new ArrayList<>();
Collections.addAll(ts,"2","3","4");
System.out.println(Collections.binarySearch(ts, "2"));
//洗牌
ArrayList<Student> blist = new ArrayList<>();
Collections.shuffle(blist);
System.out.println(alist);
//从集合中找最值
System.out.println(Collections.max(ts));
System.out.println(Collections.min(ts));
System.out.println(Collections.min(alist));
System.out.println(Collections.max(alist));
```
# MAP集合
<img src="https://gitee.com/icecat2233/picture/raw/master/20251220201802981.png" alt="image-20251220201801335" style="zoom:67%;" />
## 常用API
<img src="https://gitee.com/icecat2233/picture/raw/master/20251220201935518.png" alt="image-20251220201929102" style="zoom:67%;" />
## MAP特点
![image-20251220202017714](https://gitee.com/icecat2233/picture/raw/master/20251220202019112.png)
![image-20251220203224248](https://gitee.com/icecat2233/picture/raw/master/20251220203226325.png)
## Map的三种遍历方式
### 1entrySet方法
<img src="https://gitee.com/icecat2233/picture/raw/master/20251220205849706.png" alt="image-20251220205848087" style="zoom:50%;" />
```java
HashMap<String, String> m = new HashMap<>();
m.put("杏菜", "15岁");
m.put("佳树", "14岁");
m.put("温水", "15岁");
m.put("梦子", "15岁");
//用entrySet方法获取到所有键值对象
Set<Map.Entry<String, String>> entrySet = m.entrySet();
//遍历set集合获取到每一个键值对儿对象
for (Map.Entry<String, String> stringStringEntry : entrySet) {
//通过键值对对象获取每一个数值
System.out.println(stringStringEntry.getKey() + "---" + stringStringEntry.getValue());
}
```
### 2foreach方法
```Java
hs.forEach(new BiConsumer<String, List<String>>() {
@Override
public void accept(String key, List<String> value) {
System.out.print(key+"=");
List list = value;
for (int i = 0; i < list.size()-1; i++) {
System.out.print(list.get(i)+",");
}
System.out.println(list.get(value.size()-1));
}
});
```
### 3:调用keyset方法获取所有键值
![image-20251221174612093](https://gitee.com/icecat2233/picture/raw/master/20251221174613322.png)