Collection集合 ArrayList 集合 LinkedList集合的方法及其解释
来源:互联网 发布:java 计算时间差 分钟 编辑:程序博客网 时间:2024/05/22 03:06
1.Collection接口
Collection接口,List接口,Set接口,ArrayList接口,LinkedList类,HashSet类 LinkedHashSet类 都在java.util包 下。
2.LIst接口
1.它是一个有序的集合(元素存与取的顺序相同),它可以存储重复的元素
2.集合没有固定长度,而数组有固定长度
3.集合不能存储基本类型(四类八种) 只能存储其引用类型,那么想存储: 整形, 浮点型, 字符串, 字符 ,等八种基本数据类型怎么办?
这就需要进行数据类型的包装(把基本数据类型转换成相应的引用数据类型),下表是转换的类型。
byteshortintlongfloatdoublecharbooleanByteShortIntegerLongFloatDoubleCharacterBoolean
3.ArrayList 集合
底层数据结构是数组,查询快,增删慢
使用方法:
存储String类型的元素
ArrayList<String> list = new ArrayList<String>();
存储int类型的数据
ArrayList<Integer> list = new ArrayList<Integer>();
存储自定义类型的数据 (自己写了一个Phone类)
ArrayList<Phone> list = new ArrayList<Phone>();
public class Student {private String name;private int age;private double weight;public Student(String name, int age, double weight) {this.weight = weight;this.name = name;this.age = age;}}
import java.util.ArrayList;public class StuentsTest {public static void main(String[] args) {ArrayList<Student> list = new ArrayList<>();//以下定义了4个Student对象Student student1 = new Student("wanger1", 17, 57.2);Student student2 = new Student("wanger2", 18, 52.6);Student student3 = new Student("wanger3", 19, 77.3);Student student4 = new Student("wanger4", 22, 62.7);//以下调用集合的add(T)方法 存入上面定义的4个对象list.add(student1);list.add(student2);list.add(student3);list.add(student4);//此时集合中已经存才4个元素了, get()方法是获取索引上的元素Student s1 =list.get(0); //获取了第一个元素 student1 Student s2 =list.get(1); //获取了第一个元素 student2 Student s3 =list.get(2); //获取了第一个元素 student3Student s4 =list.get(3); //获取了第一个元素 student4//移除集合 0索引 上的元素 也就是删除了student1list.remove(0);//打印s2的内容System.out.println(s2.name+s2.age+s2.weight);}}
3.LInkedList集合
是单向链表 线程不安全的集合 增删快 查询慢
使用用法
存储String类型的元素
LinkedList<String> list = new LinkedList<String>();
存储int类型的数据
LinkedList<Integer> list = new LinkedList<Integer>();
存储自定义类型的数据(自己写了一个Phone类)
LinkedList<Phone> list = new LInkedList<Phone>();
增删改与上述ArrayList一样
阅读全文
0 0
- Collection集合 ArrayList 集合 LinkedList集合的方法及其解释
- 【JAVA】四 JAVA集合 Collection ArrayList LinkedList
- 集合Collection中ArrayList、LinkedList、Vector的用法详解
- java集合Collection的List ArrayList LinkedList 区别
- ArrayList,linkedList集合的学习
- ArrayList集合与LinkedList集合
- 【Java总结-集合】Java集合的Collection接口,ArrayList,LinkedList,HashSet,TreeSet
- Java集合:ArrayList、LinkedList
- 集合---ArrayList,LinkedList,Vector
- JAVA学习.JAVA集合类型Collection.List.ArrayList&LinkedList
- 集合一:Collection、Iterator、List、ArrayList、Vector、LinkedList
- 集合(二):Collection,List,ArrayList,LinkedList,Vector
- 集合类的学习--ArrayList vs LinkedList
- 集合-Arraylist和LinkedList的区别
- 集合ArrayList,LinkedList,Vector的区别
- day08-集合【LinkedList、HashSet、Collection集合体系】
- Day16 --集合框架 ArrayList LinkedList 泛型 其他有关集合的
- 集合( LinkedList,HashSet,Collection ) 总结
- Docker容器自启动
- Theano的配置
- 读入挂模版
- .Net框架与框架类库
- POJ 3468 A Simple Problem with Integers(线段树)
- Collection集合 ArrayList 集合 LinkedList集合的方法及其解释
- 开发一个基于ZXing库以及安卓Studio的二维码扫描小程序(一)
- C++动态规划算法之数字三角形系列问题:数塔及其变种
- Zephyr 操作系统
- 缓冲区溢出之环境变量
- 27. Remove Element
- mysql 把查询结果多行用逗号分隔组成一列
- 面试OR笔试8——字符最小分割
- python 继承重写父类方法