当前位置: 首页 > news >正文

集合框架07:LinkedList使用

1.视频链接:13.14 LinkedList使用_哔哩哔哩_bilibiliicon-default.png?t=O83Ahttps://www.bilibili.com/video/BV1zD4y1Q7Fw?spm_id_from=333.788.videopod.episodes&vd_source=b5775c3a4ea16a5306db9c7c1c1486b5&p=142.LinkedList集合的增删改查操作

package com.yundait.Demo01;import javax.swing.*;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;public class LinkedListDemo01 {public static void main(String[] args) {//创建集合LinkedList linkedList = new LinkedList<>();//1.添加元素Student s1 = new Student("刘德华", 30);Student s2 = new Student("张学友", 30);Student s3 = new Student("郭富城", 30);Student s4 = new Student("梁朝伟", 30);linkedList.add(s1);linkedList.add(s2);linkedList.add(s3);linkedList.add(s4);//2.删除元素
//        linkedList.remove(s1);
//        linkedList.remove( new Student("张学友", 30));System.out.println("删除后元素个数" + linkedList.size());System.out.println(linkedList.toString());//3.遍历元素//3.1使用for循环System.out.println("-------使用for循环---------");for (int i = 0; i < linkedList.size(); i++) {System.out.println((Student)linkedList.get(i));}//3.2使用增强for循环System.out.println("-------使用for循环---------");for (Object object : linkedList) {Student s = (Student) object;System.out.println(s.toString());}//3.2使用iterator迭代器System.out.println("-------使用iterator迭代器---------");Iterator iterator = linkedList.iterator();while (iterator.hasNext()){Student s = (Student) iterator.next();System.out.println(s.toString());}//3.2使用listIterator迭代器System.out.println("-------使用iterator迭代器---------");ListIterator listIterator = linkedList.listIterator();while (listIterator.hasPrevious()){Student s = (Student) listIterator.next();System.out.println(s.toString());}//4.判断元素是否在集合中System.out.println(linkedList.contains(s3));System.out.println(linkedList.isEmpty());//5.获取元素在集合中的位置System.out.println(linkedList.indexOf(s4));}
}

代码运行结果:

http://www.lryc.cn/news/462563.html

相关文章:

  • 一区鱼鹰优化算法+深度学习+注意力机制!OOA-TCN-LSTM-Attention多变量时间序列预测
  • Cesium 黑夜效果
  • leetcode动态规划(二)-斐波那契数列
  • 【MySQL】增删改查-进阶(一)
  • MacOS RocketMQ安装
  • OpenCV高级图形用户界面(6)获取指定窗口中图像的矩形区域函数getWindowImageRect()的使用
  • SpringColoud GateWay 核心组件
  • 5.计算机网络_抓包工具wireshark
  • 基于Java的车辆管理系统的设计与实现-计算机毕业设计源码41727
  • 在软件开发中低耦合和高内聚是什么,如何实现,请看文章
  • 关于MyBatis-Plus 提供Wrappers.lambdaQuery()的方法
  • C++——vector的了解与使用
  • Ubuntu设置静态IP地址
  • 力扣349.两个数组的交集
  • FreeRTOS - 软件定时器
  • Python的Atlassian第三方库的详细介绍
  • Java中的基本循环结构详解
  • 关于Git Bash中如何定义alias
  • luckfox1106初次使用
  • ab命令深入解析:ApacheBench性能测试工具
  • VSCode创建VUE项目(二)前端登录页面
  • centos 8.4学习小结
  • AI 设计工具合集
  • mac 源代码安装openresty
  • 人工智能和机器学习之线性代数(二)
  • Postman中的form-data 和 JSON 的区别
  • 网络安全基础知识点_网络安全知识基础知识篇
  • Vue.js 从入门到精通:全面解析组件化、路由与状态管理(附 Todo 案例)
  • AI Weekly#1:过去一周重要的AI资讯汇总
  • 图论刷题