【1】可以解决具体问题
【2】有设计结局的具体流程
【3】有评价这个算法的具体指标
逻辑结果、物理结构
在计算机的缓存,内存,硬盘如何组织管理数据的。重点在结构上,是按照什么结构来组织管理我们的数据。
线性表(数组,链表),图,数,栈,队列
2. 物理结构紧密结构(顺序结构),跳转结构(链式结构)
紧密结构,对应的真实结构如果是紧密结构–>典型就是:数组
数组结构:
优点:查询快
确定:插入慢
线性表逻辑结构,对应的真实结构如果是跳转结构->典型就是:链表
优点:删除元素,插入元素效率高
缺点:查询元素效率低
- 【1】数组,集合都是对多个数据进行存储操作
- ps:这里的存储指的是内存层面的存储,而不是持久化存储(.txt,avi,jpg,数据库)
- 【2】数组:特点:
- (1)数组一旦指定了长度,那么长度就被确定了,不可以更改int[] arr = new int[6];
- (2)数组一旦声明了类型以后,数组中只能存放这个类型的数据。数组中只能存放统一类型的数据 int[],arr,String[],s,double[]
- 【3】数组:缺点:
- (1)数组一旦制定了长度,那么长度就被确定了,不可以更改。
- (2)删除,增加元素,效率低
- (3)数组中实际元素的数量是没有办法获取的,没有提供对应的方法或者属性获取
- (4)数组存储:有序,可重复,对于无序的,不可重复的数组不能满足要求
- 【4】正因为上面的缺点,引入了一个新的存储数据结构—>集合
- 【5】集合一章我们会学习很多集合,为什么要学习这么多集合呢?
- 因为不同集合底层数据结构不一样。集合不一样,特点也不一样
- 方法
package com.fj.aggregate.collection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
public class Demo01 {
public static void main(String[] args) {
//创建对象:接口不能创建对象,类型实现类创建对象
Collection col = new ArrayList();
//调用方法
//集合有一个特点,只能存放引用数据类型,不能是基本数据类型
//基本数据类型自动装箱,对应包装类。 int---->Integer
col.add(18);
col.add(44);
col.add(45);
col.add(98);
System.out.println(col);
List list = Arrays.asList(new Integer[]{11, 15, 3, 7, 1});
col.addAll(list);
System.out.println(col);
//col.clear();
System.out.println(col);
System.out.println("集合中的元素数量为:"+col.size());
System.out.println("集合中的元素是否为空:"+col.isEmpty());
boolean isRemove = col.remove(15);
System.out.println(col);
System.out.println("集合中数据是否被删除:"+isRemove);
Collection col2 = new ArrayList();
col2.add(18);
col2.add(44);
col2.add(45);
Collection col3 = new ArrayList();
col3.add(18);
col3.add(44);
col3.add(45);
System.out.println(col2.equals(col3));
System.out.println(col2==col3);//地址一定不相等false
System.out.println(col3.contains(45));
}
}
- 集合的遍历
package com.fj.aggregate.collection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
public class Demo02 {
public static void main(String[] args) {
Collection col = new ArrayList();
col.add(18);
col.add(12);
col.add(11);
col.add(45);
//方式1:普通for循环 失败
//方式2:增强for循环
for(Object o:col){
System.out.println(o);
}
System.out.println("====================");
//方式3:
Iterator it = col.iterator();
while (it.hasNext()){
System.out.println(it.next());
}
}
}
1.List
2.Set
2. Map


