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

嘉祥网站建设公司专门制作小程序的公司

嘉祥网站建设公司,专门制作小程序的公司,摄影网站在线建设,有没有教做零食的网站Java基础 -- List集合1. Introduction1.1 好处1.2 常用泛型2. 交集,差集等2.1 自身的方法2.2 1.8jdk stream 新特性2.3 Apache的CollectionUtils工具类(推荐)3. 限定泛型范围4. Awakening1. Introduction 1.1 好处 代码复用,多种…
在这里插入图片描述

Java基础 -- List集合

    • 1. Introduction
      • 1.1 好处
      • 1.2 常用泛型
    • 2. 交集,差集等
      • 2.1 自身的方法
      • 2.2 1.8jdk stream 新特性
      • 2.3 Apache的CollectionUtils工具类(推荐)
    • 3. 限定泛型范围
    • 4. Awakening


在这里插入图片描述
在这里插入图片描述

在这里插入图片描述


1. Introduction

1.1 好处

  • 代码复用,多种数据类型执行相同的代码
  • 在编译期间可以检查类型是否安全,报警ClassCastException,类型转无法转换,同时所有强制性类型转换都是自动和隐式进行的,提高了代码的安全性和重用性
  • 提高代码的可读性

1.2 常用泛型

2. 交集,差集等

2.1 自身的方法

    @Testvoid demo02() {String[] arrayA = new String[] { "1", "2", "3", "4"};String[] arrayB = new String[] { "3", "4", "5", "6" };List<String> listA = Arrays.asList(arrayA);List<String> listB = Arrays.asList(arrayB);//1、交集List<String>  jiaoList = new ArrayList<>(listA);jiaoList.retainAll(listB);System.out.println(jiaoList);//输出:[3, 4]//2、差集List<String>  chaList = new ArrayList<>(listA);chaList.removeAll(listB);System.out.println(chaList);//输出:[1, 2]//3、并集 (先做差集再做添加所有)List<String>  bingList = new ArrayList<>(listA);bingList.removeAll(listB); // bingList为 [1, 2]bingList.addAll(listB);  //添加[3,4,5,6]System.out.println(bingList);//输出:[1, 2, 3, 4, 5, 6]}

2.2 1.8jdk stream 新特性

    @Testvoid demo02() {String[] arrayA = new String[]{"1", "2", "3", "4"};String[] arrayB = new String[]{"3", "4", "5", "6"};List<String> listA = Arrays.asList(arrayA);List<String> listB = Arrays.asList(arrayB);// 交集List<String> intersection = listA.stream().filter(item -> listB.contains(item)).collect(toList());System.out.println(intersection);//输出:[3, 4]// 差集 (list1 - list2)List<String> reduceList = listA.stream().filter(item -> !listB.contains(item)).collect(toList());System.out.println(reduceList);//输出:[1, 2]// 并集 (新建集合:1、是因为不影响原始集合。2、Arrays.asList不能add和remove操作。List<String> listAll = listA.parallelStream().collect(toList());List<String> listAll2 = listB.parallelStream().collect(toList());listAll.addAll(listAll2);System.out.println(listAll);//输出:[1, 2, 3, 4, 3, 4, 5, 6]// 去重并集List<String> list = new ArrayList<>(listA);list.addAll(listB);List<String> listAllDistinct = list.stream().distinct().collect(toList());System.out.println(listAllDistinct);//输出:[1, 2, 3, 4, 5, 6]}

2.3 Apache的CollectionUtils工具类(推荐)

        <dependency><groupId>org.apache.commons</groupId><artifactId>commons-collections4</artifactId><version>4.1</version></dependency>
    @Testvoid demo02() {String[] arrayA = new String[] { "1", "2", "3", "4"};String[] arrayB = new String[] { "3", "4", "5", "6" };List<String> listA = Arrays.asList(arrayA);List<String> listB = Arrays.asList(arrayB);//1、并集 unionSystem.out.println(CollectionUtils.union(listA, listB));//输出: [1, 2, 3, 4, 5, 6]//2、交集 intersectionSystem.out.println(CollectionUtils.intersection(listA, listB));//输出:[3, 4]//3、交集的补集(析取)disjunctionSystem.out.println(CollectionUtils.disjunction(listA, listB));//输出:[1, 2, 5, 6]//4、差集(扣除)System.out.println(CollectionUtils.subtract(listA, listB));//输出:[1, 2]}

3. 限定泛型范围

  • <? extends Parent> 指定了泛型类型的上限
  • <? super Child> 指定了泛型类型的下届
  • <?> 指定了没有限制的泛型类型

4. Awakening

         在一秒钟内看到本质的人和花半辈子也看不清一件事本质的人,自然是不一样的命运。
在这里插入图片描述

http://www.mmbaike.com/news/85821.html

相关文章:

  • 外贸网站建设上海百度模拟搜索点击软件
  • 怎样建立网站视频教程app运营推广是干什么
  • 配置网站开发环境域名解析
  • 自己做的网站能上传吗深圳博惠seo
  • 如何下载ppt模板免费下载网站seo哪家好
  • 网站企划设计公司福州百度推广排名优化
  • 昆山市建设局网站6百度营销登录
  • 提升自己建设自己的网站网站优化排名哪家性价比高
  • wordpress wordseo快速排名软件推荐
  • 酒店网站如何做北京百度推广客服电话多少
  • 《30天网站建设实录》seo综合查询工具下载
  • dreamweaver网站模板百度推广开户需要多少钱
  • 嵌入式应用软件开发流程seo专员是什么意思
  • 上海动易 网站电商线上推广渠道
  • 开发一个直播平台需要多少钱湖南靠谱seo优化公司
  • 做电影网站 广告收入推广公众号
  • 国外做游戏的视频网站松松软文平台
  • 网站asp木马删除网上企业推广
  • 电商网站前端设计方案百度首页快速排名系统
  • 苏州建设培训中心网站看颜色应该搜索哪些词汇
  • 怎样优化排名自己网站seo关键词排名优化系统
  • 网投网站建设百度竞价排名又叫什么
  • 娄底网站建设方案百度网站电话是多少
  • 做品牌网站怎么样百度关键词优化平台
  • 网站建设美工招聘百度竞价关键词价格查询
  • 怎么筛选一家做网站做的好的公司网络营销案例成功案例
  • 沈阳个人做网站广东东莞疫情最新消息
  • 网站建设论文的中期报告营销方法有哪几种
  • 哪里有网站建设培训班如何开发一个软件平台
  • 网站服务器有哪些类型有哪些类型有哪些类型有哪些排名第一的助勃药