java-collection集合整理0.9.4

news/2024/10/20 13:55:05/

java-集合整理0.9.0

    • 基本结构
    • 基本概念
    • 实例化举例
    • 遍历
    • 获取指定值

2024年10月17日09:43:16–0.9.0
2024年10月18日11:00:59—0.9.4

基本结构

  1. Collection 是最顶级的接口。
  2. 分为 List 和 Set 两大类。
  3. List 分为:ArrayList、LinkedList、Vector。
  4. Set 分为:HashSet、TreeSet。
  5. HashSet 又包含了 LinkedHashSet。

基本概念

  1. list是有序、可重复、有索引
  2. set是无序、不可重复、无索引
  3. list、set是单列集合
  4. map是双列结合

实例化举例

  1. 指明其实现类为ArrayList

Collection collection=new ArrayList<>();

  1. 指明其实现类为LinkedList

Collection collection=new LinkedList<>();

  1. 指明其实现类为HashSet

Collection collection=new HashSet<>();

  1. 指明其实现类为TreeSet

Collection collection=new TreeSet<>();

遍历

  1. 迭代器
java">Collection<String> coll= new ArrayList<>();
Iterator<String> it = coll.iterator();
while(it.hasNext()){String str = it.next();System.out.print(str);
}
  1. 迭代器加for
java">TreeSet<String> tree = new TreeSet<String>(Arrays.asList("234","56","577","78"));
for(Iterator<String> i=tree.iterator(); i.hasNext();){System.out.println(i.next());
}
  1. for增强
java">Collection<String> coll= new ArrayList<>();
for (String s : coll) {s="qqq";}
  1. forEach的lambda表达式
java">Collection<String> coll= new ArrayList<>();
coll.forEach((String s) ->System.out.println(s));
  1. for循环
java">Collection<String> coll= new ArrayList<>();
for(int i=0;i<coll.size();i++){System.out.print(coll.get(i));
}

获取指定值

  1. list有索引直接可通过get方法获取
  2. set没有索引,不能通过get方法获取

http://www.ppmy.cn/news/1540532.html

相关文章

OpenCV高级图形用户界面(13)选择图像中的一个矩形区域的函数selectROI()的使用

操作系统&#xff1a;ubuntu22.04 OpenCV版本&#xff1a;OpenCV4.9 IDE:Visual Studio Code 编程语言&#xff1a;C11 算法描述 允许用户在给定的图像上选择一个感兴趣区域&#xff08;ROI&#xff09;。 该功能创建一个窗口&#xff0c;并允许用户使用鼠标来选择一个 ROI。…

Java创建对象的两种方法

Java创建对象的两种方法是使用new关键字和使用反射机制。 使用new关键字&#xff1a;可以通过调用类的构造方法来创建对象。在Java中&#xff0c;通过使用new关键字后跟类的构造方法的调用来创建对象。 Person person1 new Person(); // 调用无参构造方法创建对象Person pe…

c语言经典100例

1.字符串转为数字 #include <stdio.h>int strToInt(char *s) {int num0;int sign1;int step1;if (*s -){sign -1;s;}while (*s > 0&&*s < 9){num num*10(*s-0);step 10;s;}return num*sign; }int main() {char a[10] "-1234";char *s a ;pr…

PHP 正则验证A-Z且排除某字母

都已经找到这里来了&#xff0c;相信已经尝试很多办法了&#xff0c;那么我们直接上答案 关键正则&#xff1a;(?!.*[IO]) //验证5到6个大写字母且排除I和O if (preg_match(/^(?!.*[IO])[A-Z\d]{5,6}$/u, AAAAM)) {echo "匹配成功"; } else {echo "匹配失败…

python工具方法 49 基于深度估计模型Depth-Anything-V2生成带雾图片

项目地址:https://github.com/DepthAnything/Depth-Anything-V2 模型地址:https://hf-mirror.com/depth-anything 论文地址:https://arxiv.org/abs/2406.09414 在较多的带雾目标检测算法中均是基于大气散射模型的逆向操作生成带雾图片,具体参考https://blog.csdn.net/a4862…

前后端请求一致性学习

在进行前后端分离开发项目的过程中&#xff0c;前后端同学往往需要依照接口文档的基本信息以及相应的响应格式进行接口请求的开发&#xff0c;在这个过程中涉及到常见的Get、Post、Put、Patch等等的请求&#xff0c;相应的前后端的书写格式是什么&#xff0c;这篇文章进行一个记…

循序渐进丨MogDB 5.0 远程访问 MogDB/Oracle 数据库的简便方法(使用@符号)

概述 早期的 MogDB 就提供了Postgres_fdw、Oracle_fdw、MySQL_fdw3个插件&#xff0c;用于远程访问 MogDB/Oracle/MySQL数据库。 旧的版本中&#xff0c;访问远程数据库的表&#xff0c;需要显式创建外部表&#xff0c;而在 MogDB 5.0当中&#xff0c;这种用法得到了简化&…

android:launchMode=“singleInstancePerTask“

android:launchMode"singleInstancePerTask" 是 Android 12(API Level 31) 引入的新启动模式&#xff0c;它是对现有的 singleInstance 模式的扩展。相比 singleInstance 模式&#xff0c;它为 Activity 提供了更多的灵活性&#xff0c;同时仍然保证了任务栈的独立性…