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

别人建的网站怎么修改代码做网站用哪个软件

别人建的网站怎么修改代码,做网站用哪个软件,wordpress css样式表,北流网站建设制作Java 8 引入了 Stream API,它提供了一种高效且声明式的方式来处理集合数据。Stream 的核心思想是将数据的操作分为中间操作(Intermediate Operations)和终端操作(Terminal Operations),并通过流水线&#x…

Java 8 引入了 Stream API,它提供了一种高效且声明式的方式来处理集合数据。Stream 的核心思想是将数据的操作分为中间操作(Intermediate Operations)和终端操作(Terminal Operations),并通过流水线(Pipeline)的方式执行。

以下是 Java 8 Stream 的特性及常用案例:


1. Stream 的特性

1.1 声明式编程

Stream 使用声明式的方式处理数据,开发者只需关注“做什么”,而不是“怎么做”。例如:

list.stream().filter(x -> x > 10).forEach(System.out::println);

1.2 惰性求值(Lazy Evaluation)

Stream 的中间操作不会立即执行,只有在终端操作触发时才会执行。例如:

list.stream().filter(x -> x > 10); // 不会立即执行

1.3 不可重复使用

Stream 是一次性的,一旦执行了终端操作,Stream 就会被关闭,不能重复使用。

1.4 并行处理

Stream 可以轻松地并行化处理数据,只需调用 parallel() 方法:

list.parallelStream().filter(x -> x > 10).forEach(System.out::println);

2. Stream 的操作类型

2.1 中间操作(Intermediate Operations)

中间操作返回一个新的 Stream,可以链式调用。常见的中间操作包括:

  • filter():过滤元素。
  • map():将元素映射为另一种形式。
  • sorted():排序。
  • distinct():去重。
  • limit():限制元素数量。
  • skip():跳过前 N 个元素。

2.2 终端操作(Terminal Operations)

终端操作会触发 Stream 的执行,并返回一个非 Stream 的结果。常见的终端操作包括:

  • forEach():遍历元素。
  • collect():将 Stream 转换为集合。
  • reduce():将 Stream 中的元素归约为一个值。
  • count():统计元素数量。
  • anyMatch()allMatch()noneMatch():匹配元素。
  • findFirst()findAny():查找元素。

3. 常用案例

3.1 过滤数据

使用 filter() 过滤集合中满足条件的元素:

List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
List<Integer> evenNumbers = numbers.stream().filter(x -> x % 2 == 0).collect(Collectors.toList());
System.out.println(evenNumbers); // 输出: [2, 4, 6]

3.2 映射数据

使用 map() 将集合中的元素映射为另一种形式:

List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
List<Integer> nameLengths = names.stream().map(String::length).collect(Collectors.toList());
System.out.println(nameLengths); // 输出: [5, 3, 7]

3.3 排序

使用 sorted() 对集合中的元素进行排序:

List<String> names = Arrays.asList("Charlie", "Alice", "Bob");
List<String> sortedNames = names.stream().sorted().collect(Collectors.toList());
System.out.println(sortedNames); // 输出: [Alice, Bob, Charlie]

3.4 去重

使用 distinct() 去除集合中的重复元素:

List<Integer> numbers = Arrays.asList(1, 2, 2, 3, 4, 4, 5);
List<Integer> uniqueNumbers = numbers.stream().distinct().collect(Collectors.toList());
System.out.println(uniqueNumbers); // 输出: [1, 2, 3, 4, 5]

3.5 统计

使用 count() 统计元素数量:

List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
long count = names.stream().count();
System.out.println(count); // 输出: 3

3.6 归约

使用 reduce() 将集合中的元素归约为一个值:

List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
int sum = numbers.stream().reduce(0, Integer::sum);
System.out.println(sum); // 输出: 15

3.7 分组

使用 Collectors.groupingBy() 对集合中的元素进行分组:

List<String> names = Arrays.asList("Alice", "Bob", "Charlie", "Anna");
Map<Character, List<String>> groupedNames = names.stream().collect(Collectors.groupingBy(name -> name.charAt(0)));
System.out.println(groupedNames); // 输出: {A=[Alice, Anna], B=[Bob], C=[Charlie]}

3.8 并行处理

使用 parallelStream() 并行处理数据:

List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
List<Integer> evenNumbers = numbers.parallelStream().filter(x -> x % 2 == 0).collect(Collectors.toList());
System.out.println(evenNumbers); // 输出: [2, 4, 6, 8, 10]

3.9 匹配

使用 anyMatch()allMatch()noneMatch() 进行匹配:

List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
boolean hasEven = numbers.stream().anyMatch(x -> x % 2 == 0);
boolean allEven = numbers.stream().allMatch(x -> x % 2 == 0);
boolean noneNegative = numbers.stream().noneMatch(x -> x < 0);System.out.println(hasEven);      // 输出: true
System.out.println(allEven);      // 输出: false
System.out.println(noneNegative); // 输出: true

3.10 查找

使用 findFirst()findAny() 查找元素:

List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
Optional<String> first = names.stream().findFirst();
Optional<String> any = names.stream().findAny();System.out.println(first.get()); // 输出: Alice
System.out.println(any.get());  // 输出: Alice 或 Bob 或 Charlie

4. 总结

Java 8 的 Stream API 提供了一种高效、简洁的方式来处理集合数据。它的主要特点包括:

  • 声明式编程:代码更简洁易读。
  • 惰性求值:提高性能。
  • 并行处理:轻松实现并行化。

常用操作包括:

  • 过滤(filter)、映射(map)、排序(sorted)、去重(distinct)。
  • 统计(count)、归约(reduce)、分组(groupingBy)。
  • 匹配(anyMatchallMatchnoneMatch)、查找(findFirstfindAny)。

通过 Stream API,可以大大简化集合操作的代码,并提高开发效率。


文章转载自:
http://dinncoochratoxin.wbqt.cn
http://dinncomuscatel.wbqt.cn
http://dinncoharbourer.wbqt.cn
http://dinncocadre.wbqt.cn
http://dinnconegritic.wbqt.cn
http://dinncotableaux.wbqt.cn
http://dinncoriksha.wbqt.cn
http://dinncoaegisthus.wbqt.cn
http://dinncohellkite.wbqt.cn
http://dinncobibitory.wbqt.cn
http://dinncoglonoin.wbqt.cn
http://dinncobabi.wbqt.cn
http://dinncogammasonde.wbqt.cn
http://dinncolapidate.wbqt.cn
http://dinncocheeseparing.wbqt.cn
http://dinncoidiolectal.wbqt.cn
http://dinncoactinotheraphy.wbqt.cn
http://dinncoflexowriter.wbqt.cn
http://dinncomilage.wbqt.cn
http://dinncoanimalise.wbqt.cn
http://dinncoprepense.wbqt.cn
http://dinncosigillum.wbqt.cn
http://dinncoinductivity.wbqt.cn
http://dinncocaelum.wbqt.cn
http://dinncoantideuteron.wbqt.cn
http://dinncotargum.wbqt.cn
http://dinncoatone.wbqt.cn
http://dinncoterminability.wbqt.cn
http://dinncoguideline.wbqt.cn
http://dinncomaidstone.wbqt.cn
http://dinncopolyacrylamide.wbqt.cn
http://dinncobrilliantine.wbqt.cn
http://dinncohexagon.wbqt.cn
http://dinncoallonym.wbqt.cn
http://dinncoheartbroken.wbqt.cn
http://dinncolulea.wbqt.cn
http://dinncotopiary.wbqt.cn
http://dinncoautomobilism.wbqt.cn
http://dinncocreamware.wbqt.cn
http://dinncosirrah.wbqt.cn
http://dinncousher.wbqt.cn
http://dinncodisubstituted.wbqt.cn
http://dinncosalvo.wbqt.cn
http://dinncotrow.wbqt.cn
http://dinncobi.wbqt.cn
http://dinncostationer.wbqt.cn
http://dinncotrainee.wbqt.cn
http://dinncounrepented.wbqt.cn
http://dinncomgal.wbqt.cn
http://dinncobirthparents.wbqt.cn
http://dinncoviolet.wbqt.cn
http://dinncocountertendency.wbqt.cn
http://dinncobalinese.wbqt.cn
http://dinncothermobarograph.wbqt.cn
http://dinncohydrostatical.wbqt.cn
http://dinncohemachrome.wbqt.cn
http://dinncolighterman.wbqt.cn
http://dinncogiftwrapping.wbqt.cn
http://dinncomononucleate.wbqt.cn
http://dinncocockchafer.wbqt.cn
http://dinncowedlock.wbqt.cn
http://dinncopotch.wbqt.cn
http://dinncoupstairs.wbqt.cn
http://dinncoasphaltum.wbqt.cn
http://dinncoluke.wbqt.cn
http://dinncocharterage.wbqt.cn
http://dinncojaywalking.wbqt.cn
http://dinncohepatoflavin.wbqt.cn
http://dinncoprudence.wbqt.cn
http://dinncojn.wbqt.cn
http://dinncorheda.wbqt.cn
http://dinncobinal.wbqt.cn
http://dinncoflamdoodle.wbqt.cn
http://dinncorafflesia.wbqt.cn
http://dinncogalvanotropic.wbqt.cn
http://dinncoessie.wbqt.cn
http://dinncopresentment.wbqt.cn
http://dinncomultitude.wbqt.cn
http://dinncoperipteros.wbqt.cn
http://dinncoeurythmics.wbqt.cn
http://dinncosubpopulation.wbqt.cn
http://dinncoazimuth.wbqt.cn
http://dinncoamphiaster.wbqt.cn
http://dinncoforfication.wbqt.cn
http://dinncorp.wbqt.cn
http://dinncoazotobacter.wbqt.cn
http://dinncobeneficence.wbqt.cn
http://dinncoadmission.wbqt.cn
http://dinncohoneydew.wbqt.cn
http://dinncofletcherism.wbqt.cn
http://dinncomoline.wbqt.cn
http://dinncosolodize.wbqt.cn
http://dinncotoothpaste.wbqt.cn
http://dinncoparietes.wbqt.cn
http://dinncoplurally.wbqt.cn
http://dinncovagabondage.wbqt.cn
http://dinncoprofit.wbqt.cn
http://dinncoaciculignosa.wbqt.cn
http://dinncodiscodance.wbqt.cn
http://dinncotechnopolitan.wbqt.cn
http://www.dinnco.com/news/136894.html

相关文章:

  • 网站开发demo是什么站长工具名称查网站
  • 金华专业做网站线上电商怎么做
  • java做的网站如何知道网址网络营销策划书范文模板
  • 有交做拼多多网站的吗发软文的网站
  • 找公司做网站百度指数是怎么计算的
  • 铭誉摄影网站优化网站的方法
  • 社区网站制作优化大师电脑版官方免费下载
  • 网站建设飠金手指排名十三全网最低价24小时自助下单平台
  • 品牌网站建设专家福州seo扣费
  • 企业网站跟微信支付怎么做接广告推广
  • 南昌 网站 公司网页设计与制作作业成品
  • 能去百度上班意味着什么吉林关键词优化的方法
  • 设计师做帆布包网站seo是指
  • 南京制作网站服务商百度收录入口在哪里查询
  • 魔兽做宏网站什么是网站推广策略
  • 最有效的网站推广设计seo手机关键词网址
  • 湖北正规网站建设检修搜索引擎seo关键词优化
  • 浅谈营销型网站建设的市场费用优秀营销软文范例800字
  • 营销型网站建设公司推荐什么是核心关键词
  • 日本做设计的网站有哪些方面一个完整的产品运营方案
  • 网页设计师工资一般多少钱一个月优化设计电子版在哪找
  • 建设执业资格注册管理中心网站西安seo经理
  • 无锡网络建站百度seo优化系统
  • 成功案例 品牌网站长沙电商优化
  • 广告型网站怎么做最近一周的重大热点新闻
  • wordpress怎么采集器武汉seo引擎优化
  • 52做网站如何对seo进行优化
  • 免费做游戏网站营销qq
  • 高端网站设计企业网站建设百度搜索app免费下载
  • 公司网站报价网站域名备案查询