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

网站推广要我营业执照复印件西宁网络推广公司

网站推广要我营业执照复印件,西宁网络推广公司,昆山那个网站推广好,搜索网站建设使用 CollectionUtils 类的常用方法 在Java开发中#xff0c;我们经常需要对集合进行各种操作#xff0c;而Apache Commons Collections库提供了一个方便的工具类 CollectionUtils#xff0c;其中包含了许多实用的方法。在这篇博客中#xff0c;我们将深入了解一些常用的方…使用 CollectionUtils 类的常用方法 在Java开发中我们经常需要对集合进行各种操作而Apache Commons Collections库提供了一个方便的工具类 CollectionUtils其中包含了许多实用的方法。在这篇博客中我们将深入了解一些常用的方法并提供详细的示例。 1. isEmpty // Check if a list is empty ListString emptyList new ArrayList(); boolean isEmpty CollectionUtils.isEmpty(emptyList); System.out.println(Is the list empty? isEmpty);//Is the list empty? true这个方法用于检查给定的集合是否为空。在上面的例子中我们创建了一个空的 ArrayList然后使用 isEmpty 方法检查它是否为空最后打印结果。 2. isNotEmpty // Check if a list is not empty ListString nonEmptyList Arrays.asList(item1, item2); boolean isNotEmpty CollectionUtils.isNotEmpty(nonEmptyList); System.out.println(Is the list not empty? isNotEmpty);//Is the list empty? true与 isEmpty 相反isNotEmpty 方法用于检查集合是否不为空。我们创建了一个包含一些元素的列表并使用 isNotEmpty 方法进行检查。 isEmpty 和 isNotEmpty 时间复杂度 O(1) - 常数时间。这是因为这两个方法只需检查集合是否为 null 或其大小是否为零。适用场景 用于快速检查集合是否为空。 3. size // Get the size of a list int size CollectionUtils.size(nonEmptyList); System.out.println(Size of the list: size);//Size of the list: 2size 方法返回给定集合的大小。在这个例子中我们获取了之前非空列表的大小并打印输出。 size 时间复杂度 O(1) - 常数时间。这是因为 size 方法通常由集合实现提供直接返回已存储的大小。适用场景 适用于快速获取集合的大小。 4. addAll // Merge two lists ListString destinationList new ArrayList(); CollectionUtils.addAll(destinationList, item3, item4); System.out.println(Merged list: destinationList);//Merged list: [item3, item4]addAll 方法用于将一个集合的所有元素添加到另一个集合中。在这里我们创建了一个目标列表并使用 addAll 将两个元素添加到这个列表中。 addAll 时间复杂度 O(n) - 线性时间其中 n 是要添加的元素数量。适用场景 用于将一个集合的所有元素添加到另一个集合。在元素数量较大时可能会影响性能。 5. removeAll // Remove elements from a list CollectionUtils.removeAll(destinationList, item3); System.out.println(List after removal: destinationList);//List after removal: []removeAll 方法用于从集合中移除指定的元素。在这个例子中我们从目标列表中移除了一个元素并打印输出修改后的列表。 removeAll 时间复杂度 O(n) - 线性时间其中 n 是要移除的元素数量。适用场景 用于从集合中移除指定的元素。 6. intersection // Get the intersection of two lists ListString list1 Arrays.asList(apple, orange, banana); ListString list2 Arrays.asList(banana, kiwi, apple); ListString intersection (ListString) CollectionUtils.intersection(list1, list2); System.out.println(Intersection of lists: intersection);//Intersection of lists: [banana, apple]intersection 方法返回两个集合的交集。在这里我们创建了两个包含水果的列表并使用 intersection 方法获取它们的交集。 7. union // Get the union of two lists ListString union (ListString) CollectionUtils.union(list1, list2); System.out.println(Union of lists: union);//Union of lists: [apple, orange, banana, kiwi]union 方法返回两个集合的并集。在这个例子中我们使用 union 方法获取两个水果列表的并集。 8. disjunction // Get the disjunction of two lists ListString disjunction (ListString) CollectionUtils.disjunction(list1, list2); System.out.println(Disjunction of lists: disjunction);//Disjunction of lists: [orange, kiwi]disjunction 方法返回两个集合的互斥集合即不属于交集的部分。在这里我们使用 disjunction 方法获取两个列表的互斥部分。 9. subtract // Subtract one list from another CollectionUtils.subtract(list1, list2); System.out.println(List1 after subtracting list2: list1);//List1 after subtracting list2: [orange]subtract 方法用于从第一个集合中移除第二个集合中包含的元素。在这个例子中我们使用 subtract 方法从 list1 中移除了与 list2 重叠的元素。 subtract 时间复杂度 O(m n) - 线性时间其中 m 和 n 分别是两个集合的大小。适用场景 用于从一个集合中移除另一个集合包含的元素。 10. filter // Filter elements based on a condition ListString filteredList (ListString) CollectionUtils.select(list1, s - s.startsWith(a)); System.out.println(Filtered list: filteredList);//Filtered list: [apple]filter 方法根据给定的条件保留集合中的元素。在这里我们使用 filter 方法保留了以字母 “a” 开头的元素。 filter 时间复杂度 O(n) - 线性时间其中 n 是集合的大小。适用场景 用于根据条件筛选集合中的元素。 11. transform // Transform elements in a list ListInteger lengths (ListInteger) CollectionUtils.collect(list1, String::length); System.out.println(Lengths of items in the list: lengths);//Lengths of items in the list: [5, 6, 6]transform 方法用于对集合中的元素进行转换。在这个例子中我们使用 transform 方法获取了 list1 中每个字符串元素的长度并将结果存储在 lengths 列表中。 transform 时间复杂度 O(n) - 线性时间其中 n 是集合的大小。适用场景 用于对集合中的元素进行转换。 12. countMatches // Count elements that match a condition long count CollectionUtils.countMatches(list1, s - s.length() 5); System.out.println(Number of items with length 5: count);//Number of items with length 5: 2countMatches 方法用于计算满足特定条件的元素数量。在这个例子中我们计算了 list1 中长度大于 5 的元素的数量。 countMatches 时间复杂度 O(n) - 线性时间其中 n 是集合的大小。适用场景 用于计算满足特定条件的元素数量。
http://www.hkea.cn/news/14377662/

相关文章:

  • 邢台提供网站建设公司哪家好WordPress导航类主题主题
  • 有了域名和主机怎么做网站个人网页设计排版
  • 济南城乡建设官方网站百度网站免费优化软件下载
  • 网站怎么经营做网站背景音乐
  • 免费注册一个网站网站建设最贵多少钱
  • 建站能赚钱吗在线制作网站乔拓云
  • ASP做购物网站视频旧宫网站建设
  • 广州做网站优化费用自己怎么手机做网站
  • 网站建设的费用需求做优化的网站
  • 设计得好的美食网站图片编辑工具免费版
  • 帮客户做网站挣钱吗免费个人网站建设
  • 飞凡 做电商网站优化就是开除吗
  • WordPress找不到站点备案查询入口
  • 韩国网站设计风格网站建设设计公司+知乎
  • 南宁网站设计方案网站建设丿金手指下拉
  • 个人网站建设 优帮云wordpress采集视频插件
  • 重庆高端网站设计公司做彩票网站能挣到钱吗?
  • 天猫开店流程及费用2023优化方案数学2024电子版
  • 那些企业需要做网站佛山市城乡住房建设局网站
  • 做网站去哪里找广告主群晖非插件搭建wordpress
  • 贵阳住房城乡建设部网站wordpress安装乱码
  • 关于网站建设项目实训报告如何查看网站备案
  • dede做的网站怎样去换模版网站 用php asp源码 比较好
  • 足彩网站怎样做推广即时设计网站
  • 哈尔滨模板网站建设微信小程序怎么申请注册
  • 广告网眼布网站优化建设扬州
  • 临武县网站建设wordpress的模板目录在哪里
  • 聚美优品网站建设主题北京网站建设 义创
  • 淘宝建设网站首页WordPress音乐免刷新
  • 常州市城乡建设局网站郑州市有做网站的吗