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

Java工具--stream流

Java工具--stream流

  • 过滤(filter)
  • 统计
    • 求最大最小和均值
    • 求和(sum)
    • 过滤后,对数据进行统计
  • 遍历(map)
  • 规约(reduce)
  • 排序(sorted)
  • 去重(distinct)
  • findAny() 和 findFirst()
  • 判断(anyMatch,allMatch,noneMatch)
  • 分组
  • toList() toSet() toMap()

过滤(filter)

List<Integer> numberList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
List<String> StringList = Arrays.asList("apple", "orange", "banana", "grape", "apple", "kiwi");// 筛选出所有的偶数  >>>[2, 4, 6, 8, 10]
List<Integer> evenList = numberList.stream().filter(num -> num%2==0).collect(Collectors.toList());
// 筛选出所有非a开头的字符串  >>>[orange, banana, grape, kiwi]
List<String> strList = StringList.stream().filter(item -> !item.startsWith("a")).collect(Collectors.toList());

统计

求最大最小和均值

使用 mapToInt() 求整数列表中的最大值、最小值、总和、平均值。

List<Integer> numberList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
// 10
int max = numberList.stream().mapToInt(Integer::intValue).max().getAsInt();
// 1
int min = numberList.stream().mapToInt(Integer::intValue).min().getAsInt();
// 55
int min = numberList.stream().mapToInt(Integer::intValue).sum();
// 5.5
double avg = numberList.stream().mapToInt(Integer::intValue).average().getAsDouble();// 计算双精度列表中所有数字的平均值
List<Double> doubleList = Arrays.asList(1.1, 2.2, 3.3, 4.2, 5.2, 6.1);
// 3.6833333333333336
double average = doubleList.stream().reduce(0.0, (a, b) -> a + b) / doubleList.size();
double average2 = doubleList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
//获取年龄最大的学生
Student ageMaxStudent = list.stream().max(Comparator.companing(Student::getAge)).get();//获取年龄最小的学生
Student ageMinStudent  = list.stream().min(Comparator.companing(Student::getAge)).get();

求和(sum)

List<Integer> numberList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
List<Double> doubleList = Arrays.asList(1.1, 2.2, 3.3, 4.2, 5.2, 6.1);
List<Long> longNumberList = Arrays.asList(10L, 30L, 50L, 60L, 70L, 80L, 90L);// 55
int m = numberList.stream().mapToInt(Integer::intValue).sum();
// 22.1
double n = doubleList.stream().mapToDouble(Double::doubleValue).sum();
// 390
long w = longNumberList.stream().mapToLong(Long::longValue).sum();
// 55
int sum1 = numberList.stream().reduce(0, (a, b) -> a + b);
int sum2 = numberList.stream().reduce(0, Integer::sum);

过滤后,对数据进行统计

// 计算整数列表中所有偶数的和  >>>30
int sum = numberList.stream().filter(num -> num%2==0).mapToInt(Integer::intValue).sum();// 统计长度大于5的字符串数量  >>>2
long count = StringList.stream().filter(str -> str.length()>5).count();// 查找字符串列表中所有字符串的长度的总和  >>>31
int lengthSum = StringList.stream().mapToInt(String::length).reduce(0, Integer::sum);

遍历(map)

List<Integer> numberList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
List<String> StringList = Arrays.asList("apple", "orange", "banana", "grape", "apple", "kiwi");// 以整数列表作为输入,返回每个元素的平方的新列表  >>>[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
List<Integer> squareList = numberList.stream().map(num -> num*num).collect(Collectors.toList());
// 以字符串列表作为输入,返回每个字符串的长度的新列表  >>>[5, 6, 6, 5, 5, 4]
// map中的方法可以简化成 .map(String::length)
List<Integer> lenList = StringList.stream().map(item -> item.length()).collect(Collectors.toList());

规约(reduce)

List<Integer> numberList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);// 10
int maxNum = numberList.stream().reduce(Integer::max).get();
// 1
int minNum = numberList.stream().reduce(Integer::min).get();
// 55
int sumNum = numberList.stream().reduce(0, Integer::sum);
// 55
int sum = numberList.stream().reduce(0, (a, b) -> a + b);
// 3628800
int product = numberList.stream().reduce(1, (a, b) -> a * b);
List<Integer> numberList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
List<String> StringList = Arrays.asList("apple", "orange", "banana", "grape", "apple", "kiwi");// 在整数列表中找出最大元素  >>>10
int max = numberList.stream().reduce(0, (a, b) -> a>b? a : b);
// 查找字符串列表中最长的字符串  >>>Optional[banana]
String maxLengthStr = StringList.stream().reduce((s1, s2) -> s1.length() > s2.length()? s1 : s2).toString();
// 查找字符串列表中最短的字符串  >>>Optional[kiwi]
String minLengthStr = StringList.stream().reduce((s1, s2) -> s1.length() < s2.length()? s1 : s2).toString();

将列表中的所有字符串连接成一个字符串

// apple@orange@banana@grape@apple@kiwi@
String concat1 = StringList.stream().reduce("", (a, b) -> a + b + "@");
// apple@orange@banana@grape@apple@kiwi
String concat2 = StringList.stream().collect(Collectors.joining("@"));
// apple@orange@banana@grape@apple@kiwi
String concat3 = String.join("@", StringList);

排序(sorted)

List<String> StringList = Arrays.asList("apple", "orange", "banana", "grape", "apple", "kiwi");// 将每个字符串装换为大写,然后按字母顺序排序
// [APPLE, APPLE, BANANA, GRAPE, KIWI, ORANGE]
List<String> sortedUpperCase = StringList.stream().map(String::toUpperCase).sorted().collect(Collectors.toList());
List<Integer> numberList = Arrays.asList(12, 2, 33, 24, 5, 61, 27, 8, 39, 10);// 升序  >>>[2, 5, 8, 10, 12, 24, 27, 33, 39, 61]
List<Integer> sort1NumberList = numberList.stream().sorted().collect(Collectors.toList());
List<Integer> sort2NumberList = numberList.stream().sorted(Comparator.comparing(item->item)).collect(Collectors.toList());
// 降序   >>>[61, 39, 33, 27, 24, 12, 10, 8, 5, 2]
List<Integer> sortReverseNumberList = numberList.stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList());// 降序  >>>[61, 39, 33, 27, 24, 12, 10, 8, 5, 2]
List<Integer> numberList1 = Arrays.asList(12, 2, 33, 24, 5, 61, 27, 8, 39, 10);
numberList1.sort((objectA, objectB) -> objectB.compareTo(objectA));
// 升序  >>>[2, 5, 8, 10, 12, 24, 27, 33, 39, 61]
List<Integer> numberList2 = Arrays.asList(12, 2, 33, 24, 5, 61, 27, 8, 39, 10);
numberList2.sort((objectA, objectB) -> objectA.compareTo(objectB));

若需要排序的不是简单数字列表,是对象列表
List sortNumberList = numberList.stream().sorted(Comparator.comparing(item->item.getAge())).collect(Collectors.toList());
studentList.sort((objectA, objectB) -> objectB.getAge().compareTo(objectA.getAge()));

去重(distinct)

// 去重   >>>[apple, orange, banana, grape, kiwi]
List<String> unique = StringList.stream().distinct().collect(Collectors.toList());

findAny() 和 findFirst()

使用 findAny() 和 findFirst() 获取第一条数据。

List<String> stringList = Arrays.asList("apple", "orange", "banana", "grape", "apple", "kiwi");String str1 = stringList.stream().filter(item -> item.endsWith("e")).findAny().orElse(null);
String str2 = stringList.stream().filter(item -> item.endsWith("e")).findAny().orElse(null);

findFirst() 和 findAny() 都是获取列表中的第一条数据,但是findAny()操作,返回的元素是不确定的,对于同一个列表多次调用findAny()有可能会返回不同的值。使用findAny()是为了更高效的性能。如果是数据较少,串行地情况下,一般会返回第一个结果,如果是并行(parallelStream并行流)的情况,那就不能确保是第一个。

判断(anyMatch,allMatch,noneMatch)

  1. anyMatch(T -> boolean)
    使用 anyMatch(T -> boolean) 判断流中是否有一个元素匹配给定的 T -> boolean 条件。
  2. allMatch(T -> boolean)
    使用 allMatch(T -> boolean) 判断流中是否所有元素都匹配给定的 T -> boolean 条件。
  3. noneMatch(T -> boolean)
    使用 noneMatch(T -> boolean) 流中是否没有元素匹配给定的 T -> boolean 条件。
List<String> stringList = Arrays.asList("apple", "orange", "grape", "apple");
List<Integer> numberList = Arrays.asList(12, 2, 33, 24, 5, 61, 27, 8, 39, 10);// 存在元素以a开头   >>>true
boolean anyStartsWithA = stringList.stream().anyMatch(item -> item.startsWith("a"));
// 所有元素以e结尾   >>>true
boolean allEndsWithB = stringList.stream().allMatch(item -> item.endsWith("e"));
// 没有元素以g开头   >>>false
boolean noneStartsWithG = stringList.stream().noneMatch(item -> item.startsWith("g"));
// 没有元素以k开头   >>>true
boolean noneStartsWithK = stringList.stream().noneMatch(item -> item.startsWith("k"));
// 所有元素都是偶数   >>>false
boolean allEven = numberList.stream().allMatch(item -> item%2==0);

分组

	@Testpublic void test011() {// User对象的四个属性,(id,areaCode,name,roomNum,peopleNum)List<User> userList = new ArrayList<>();userList.add(new User(1L, "210300", "熊大",1, 2));userList.add(new User(2L, "210300", "赵二",2, 3));userList.add(new User(3L, "210100", "张三",3, 4));userList.add(new User(4L, "210100", "李四",4, 5));userList.add(new User(5L, "210400", "王五",5, 6));/**  返回一个Map,其中键是areaCode,值是具有该areaCode的用户列表* {*  210400=[User(id=5, areaCode=210400, name=王五, roomNum=5, peopleNum=6)],*  210300=[User(id=1, areaCode=210300, name=熊大, roomNum=1, peopleNum=2), User(id=2, areaCode=210300, name=赵二, roomNum=2, peopleNum=3)],*  210100=[User(id=3, areaCode=210100, name=张三, roomNum=3, peopleNum=4), User(id=4, areaCode=210100, name=李四, roomNum=4, peopleNum=5)]*  }*/Map<String, List<User>> areaCodeAndUserMap = userList.stream().collect(Collectors.groupingBy(User::getAreaCode));/** 按areaCode分组,并收集组中roomNum最大的User对象* {* 210400=Optional[User(id=5, areaCode=210400, name=王五, roomNum=5, peopleNum=6)],* 210300=Optional[User(id=2, areaCode=210300, name=赵二, roomNum=2, peopleNum=3)],* 210100=Optional[User(id=4, areaCode=210100, name=李四, roomNum=4, peopleNum=5)]* }*/Map<String, Optional<User>> areaCodeAndMaxRoomMap = userList.stream().collect(Collectors.groupingBy(User::getAreaCode,Collectors.maxBy(Comparator.comparingInt(User::getRoomNum))));// 按areaCode分组,并将组中的userID收集为List// {210400=[5], 210300=[1, 2], 210100=[3, 4]}Map<String, List<Long>> areaCodeAndUserIdMap = userList.stream().collect(Collectors.groupingBy(User::getAreaCode,Collectors.mapping(User::getId, Collectors.toList())));// 按areaCode分组,并统计个数// {210400=1, 210300=2, 210100=2}Map<String, Long> areaCodeNumMap = userList.stream().collect(Collectors.groupingBy(User::getAreaCode, Collectors.counting()));// 按areaCode分组,并统计组中的roomNum平均值// {210400=5.0, 210300=1.5, 210100=3.5}Map<String, Double> areaCodeAndRoomSumMap = userList.stream().collect(Collectors.groupingBy(User::getAreaCode, Collectors.averagingInt(User::getRoomNum)));// 按areaCode分组,并统计组中的roomNum和// {210400=5, 210300=3, 210100=7}Map<String, Integer> areaCodeAndRoomNumMap = userList.stream().collect(Collectors.groupingBy(User::getAreaCode, Collectors.summingInt(User::getRoomNum)));// 按areaCode分组,并统计组中的peopleNum和// {210400=6, 210300=5, 210100=9}Map<String, Integer> areaCodeAndPeopleNumMap = userList.stream().collect(Collectors.groupingBy(User::getAreaCode, Collectors.summingInt(User::getPeopleNum)));}@Data@NoArgsConstructor@AllArgsConstructorclass User{private Long id;private String areaCode;private String name;private Integer roomNum;private Integer peopleNum;}
List<String> StringList = Arrays.asList("apple", "orange", "banana", "grape", "apple", "kiwi");// 按字符串长度分组
Map<Integer, List<String>> groups = new HashMap<>();
for (String item : StringList) {int length = item.length();if (!groups.containsKey(length)) {groups.put(length, new ArrayList<>());}groups.get(length).add(item);
}// {4=[kiwi], 5=[apple, grape, apple], 6=[orange, banana]}
System.out.println(groups);

toList() toSet() toMap()

用toMap方法时,必须确保选择的key是唯一且非空的

@Test
public void test011() {// User对象的四个属性,(id,areaCode,name,roomNum,peopleNum)List<User> userList = new ArrayList<>();userList.add(new User(1L, "210300", "熊大",1, 2));userList.add(new User(2L, "210300", "赵二",2, 3));userList.add(new User(3L, "210100", "张三",3, 4));userList.add(new User(4L, "210100", "李四",4, 5));userList.add(new User(5L, "210400", "王五",5, 6));// [210300, 210300, 210100, 210100, 210400]List<String> list1 = userList.stream().map(User::getAreaCode).collect(Collectors.toList());// [210400, 210300, 210100]Set<String> set1 = userList.stream().map(User::getAreaCode).collect(Collectors.toSet());/*** {* 李四=User(id=4, areaCode=210100, name=李四, roomNum=4, peopleNum=5), * 张三=User(id=3, areaCode=210100, name=张三, roomNum=3, peopleNum=4), * 熊大=User(id=1, areaCode=210300, name=熊大, roomNum=1, peopleNum=2), * 赵二=User(id=2, areaCode=210300, name=赵二, roomNum=2, peopleNum=3), * 王五=User(id=5, areaCode=210400, name=王五, roomNum=5, peopleNum=6)* }*/Map<String, User> map1 = userList.stream().collect(Collectors.toMap(User::getName, Function.identity()));/*** {* 1=User(id=1, areaCode=210300, name=熊大, roomNum=1, peopleNum=2), * 2=User(id=2, areaCode=210300, name=赵二, roomNum=2, peopleNum=3), * 3=User(id=3, areaCode=210100, name=张三, roomNum=3, peopleNum=4), * 4=User(id=4, areaCode=210100, name=李四, roomNum=4, peopleNum=5), * 5=User(id=5, areaCode=210400, name=王五, roomNum=5, peopleNum=6)* }*/Map<Long, User> map2 = userList.stream().collect(Collectors.toMap(User::getId, Function.identity()));// {李四=5, 张三=4, 熊大=2, 赵二=3, 王五=6}Map<String, Integer> map3 = userList.stream().collect(Collectors.toMap(User::getName, User::getPeopleNum));// {1=熊大, 2=赵二, 3=张三, 4=李四, 5=王五}Map<String, String> map4 = userList.stream().collect(Collectors.toMap(item -> String.valueOf(item.getId()),User::getName));}

相关文章:

Java工具--stream流

Java工具--stream流 过滤&#xff08;filter&#xff09;统计求最大最小和均值求和&#xff08;sum&#xff09;过滤后&#xff0c;对数据进行统计 遍历&#xff08;map&#xff09;规约&#xff08;reduce&#xff09;排序&#xff08;sorted&#xff09;去重&#xff08;dist…...

什么是 JWT?它是如何工作的?

松哥最近辅导了几个小伙伴秋招&#xff0c;有小伙伴在面小红书时遇到这个问题&#xff0c;这个问题想回答全面还是有些挑战&#xff0c;松哥结合之前的一篇旧文和大伙一起来聊聊。 一 无状态登录 1.1 什么是有状态 有状态服务&#xff0c;即服务端需要记录每次会话的客户端信…...

微信小程序使用picker,数组怎么设置默认值

默认先显示请选择XXX。然后点击弹出选择列表。如果默认value是0的话&#xff0c;他就直接默认显示数组的第一个了。<picker mode"selector" :value"planIndex" :range"planStatus" range-key"label" change"bindPlanChange&qu…...

Springboot生成树工具类,可通过 id/code 编码生成 2.0版本

优化工具类中&#xff0c;查询父级时便利多次的问题 import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.mutable.MutableLong; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; import org.spri…...

17、CPU缓存架构详解高性能内存队列Disruptor实战

1.CPU缓存架构详解 1.1 CPU高速缓存概念 CPU缓存即高速缓冲存储器&#xff0c;是位于CPU与主内存间的一种容量较小但速度很高的存储器。CPU高速缓存可以分为一级缓存&#xff0c;二级缓存&#xff0c;部分高端CPU还具有三级缓存&#xff0c;每一级缓存中所储存的全部数据都是…...

算法训练营打卡Day18

目录 二叉搜索树的最小绝对差二叉搜索树中的众数二叉树的最近公共祖先额外练手题目 题目1、二叉搜索树的最小绝对差 力扣题目链接(opens new window) 给你一棵所有节点为非负值的二叉搜索树&#xff0c;请你计算树中任意两节点的差的绝对值的最小值。 示例&#xff1a; 思…...

【leetcode】169.多数元素

boyer-moore算法最简单理解方法&#xff1a; 假设你在投票选人 如果你和候选人&#xff08;利益&#xff09;相同&#xff0c;你就会给他投一票&#xff08;count1&#xff09;&#xff0c;如果不同&#xff0c;你就会踩他一下&#xff08;count-1&#xff09;当候选人票数为0&…...

MyBatis<foreach>标签的用法与实践

foreach标签简介 实践 demo1 简单的一个批量更新&#xff0c;这里传入了一个List类型的集合作为参数&#xff0c;拼接到 in 的后面 &#xff0c;来实现一个简单的批量更新 <update id"updateVislxble" parameterType"java.util.List">update model…...

R语言Shiny包新手教程

R语言Shiny包新手教程 1. 简介 Shiny 是一个 R 包&#xff0c;用于创建交互式网页应用。它非常适合展示数据分析结果和可视化效果。 2. 环境准备 安装R和RStudio 确保你的计算机上安装了 R 和 RStudio。你可以从 CRAN 下载 R&#xff0c;或从 RStudio 官网 下载 RStudio。…...

[大象快讯]:PostgreSQL 17 重磅发布!

家人们&#xff0c;数据库界的大新闻来了&#xff01;&#x1f4e3; PostgreSQL 17 正式发布&#xff0c;全球开发者社区的心血结晶&#xff0c;带来了一系列令人兴奋的新特性和性能提升。 发版通告全文如下 PostgreSQL 全球开发小组今天&#xff08;2024-09-26&#xff09;宣布…...

CHI trans--Home节点发起的操作

总目录&#xff1a; CHI协议简读汇总-CSDN博客https://blog.csdn.net/zhangshangjie1/article/details/131877216 Home节点能够发起的操作&#xff0c;包含如下几类&#xff1a; Home to Subordinate Read transactionsHome to Subordinate Write transactionsHome to Subor…...

Rust和Go谁会更胜一筹

在国内&#xff0c;我认为Go语言会成为未来的主流&#xff0c;因为国内程序员号称码农&#xff0c;比较适合搬砖&#xff0c;而Rust对心智要求太高了&#xff0c;不适合搬砖。 就个人经验来看&#xff0c;Go语言简单&#xff0c;下限低&#xff0c;没有什么心智成本&#xff0c…...

记HttpURLConnection下载图片

目录 一、示例代码1 二、示例代码2 一、示例代码1 import java.io.*; import java.net.HttpURLConnection; import java.net.URL;public class Test {/*** 下载图片*/public void getNetImg() {InputStream inStream null;FileOutputStream fOutStream null;try {// URL 统…...

物联网实训室建设的必要性

物联网实训室建设的必要性 一、物联网发展的背景 物联网&#xff08;IoT&#xff09;是指通过信息传感设备&#xff0c;按照约定的协议&#xff0c;将任何物品与互联网连接起来&#xff0c;进行信息交换和通信&#xff0c;以实现智能化识别、定位、跟踪、监控和管理的一种网络…...

初识C语言(四)

目录 前言 十一、常见关键字&#xff08;补充&#xff09; &#xff08;1&#xff09;register —寄存器 &#xff08;2&#xff09;typedef类型重命名 &#xff08;3&#xff09;static静态的 1、修饰局部变量 2、修饰全局变量 3、修饰函数 十二、#define定义常量和宏…...

产品架构图:从概念到实践

在当今快速发展的科技时代&#xff0c;产品架构图已成为产品经理和设计师不可或缺的工具。它不仅帮助我们理解复杂的产品体系&#xff0c;还能指导我们进行有效的产品设计和开发。本文将深入探讨产品架构图的概念、重要性以及绘制方法。 整个内容框架分为三个部分&#xff0c;…...

smartctl 命令:查看硬盘健康状态

一、命令简介 ​smartctl​ 命令用于获取硬盘的 SMART 信息。 介绍硬盘SMART 硬盘的 SMART (Self-Monitoring, Analysis, and Reporting Technology) 技术用于监控硬盘的健康状态&#xff0c;并能提供一些潜在故障的预警信息。通过查看 SMART 数据&#xff0c;用户可以了解硬…...

BBR 为什么没有替代 CUBIC 成为 Linux 内核缺省算法

自 2017 年底 bbr 发布以来&#xff0c;随着媒体的宣讲&#xff0c;各大站点陆续部署 bbr&#xff0c;很多网友不禁问&#xff0c;bbr 这么好&#xff0c;为什么不替代 cubic 成为 linux 的缺省算法。仅仅因为它尚未标准化&#xff1f;这么好的算法又为什么没被标准化&#xff…...

Git忽略规则原理和.gitignore文件不生效的原因和解决办法

在使用Git进行版本控制时&#xff0c;.gitignore文件扮演着至关重要的角色。它允许我们指定哪些文件或目录应该被Git忽略&#xff0c;从而避免将不必要的文件&#xff08;如日志文件、编译产物等&#xff09;纳入版本控制中。然而&#xff0c;在实际使用过程中&#xff0c;有时…...

MySQL-数据库设计

1.范式 数据库的范式是⼀组规则。在设计关系数据库时&#xff0c;遵从不同的规范要求&#xff0c;设计出合理的关系型数 据库&#xff0c;这些不同的规范要求被称为不同的范式。 关系数据库有六种范式&#xff1a;第⼀范式&#xff08;1NF&#xff09;、第⼆范式&#xff08;…...

XML Group端口详解

在XML数据映射过程中&#xff0c;经常需要对数据进行分组聚合操作。例如&#xff0c;当处理包含多个物料明细的XML文件时&#xff0c;可能需要将相同物料号的明细归为一组&#xff0c;或对相同物料号的数量进行求和计算。传统实现方式通常需要编写脚本代码&#xff0c;增加了开…...

web vue 项目 Docker化部署

Web 项目 Docker 化部署详细教程 目录 Web 项目 Docker 化部署概述Dockerfile 详解 构建阶段生产阶段 构建和运行 Docker 镜像 1. Web 项目 Docker 化部署概述 Docker 化部署的主要步骤分为以下几个阶段&#xff1a; 构建阶段&#xff08;Build Stage&#xff09;&#xff1a…...

XCTF-web-easyupload

试了试php&#xff0c;php7&#xff0c;pht&#xff0c;phtml等&#xff0c;都没有用 尝试.user.ini 抓包修改将.user.ini修改为jpg图片 在上传一个123.jpg 用蚁剑连接&#xff0c;得到flag...

ES6从入门到精通:前言

ES6简介 ES6&#xff08;ECMAScript 2015&#xff09;是JavaScript语言的重大更新&#xff0c;引入了许多新特性&#xff0c;包括语法糖、新数据类型、模块化支持等&#xff0c;显著提升了开发效率和代码可维护性。 核心知识点概览 变量声明 let 和 const 取代 var&#xf…...

以下是对华为 HarmonyOS NETX 5属性动画(ArkTS)文档的结构化整理,通过层级标题、表格和代码块提升可读性:

一、属性动画概述NETX 作用&#xff1a;实现组件通用属性的渐变过渡效果&#xff0c;提升用户体验。支持属性&#xff1a;width、height、backgroundColor、opacity、scale、rotate、translate等。注意事项&#xff1a; 布局类属性&#xff08;如宽高&#xff09;变化时&#…...

前端开发面试题总结-JavaScript篇(一)

文章目录 JavaScript高频问答一、作用域与闭包1.什么是闭包&#xff08;Closure&#xff09;&#xff1f;闭包有什么应用场景和潜在问题&#xff1f;2.解释 JavaScript 的作用域链&#xff08;Scope Chain&#xff09; 二、原型与继承3.原型链是什么&#xff1f;如何实现继承&a…...

深入解析C++中的extern关键字:跨文件共享变量与函数的终极指南

&#x1f680; C extern 关键字深度解析&#xff1a;跨文件编程的终极指南 &#x1f4c5; 更新时间&#xff1a;2025年6月5日 &#x1f3f7;️ 标签&#xff1a;C | extern关键字 | 多文件编程 | 链接与声明 | 现代C 文章目录 前言&#x1f525;一、extern 是什么&#xff1f;&…...

云原生玩法三问:构建自定义开发环境

云原生玩法三问&#xff1a;构建自定义开发环境 引言 临时运维一个古董项目&#xff0c;无文档&#xff0c;无环境&#xff0c;无交接人&#xff0c;俗称三无。 运行设备的环境老&#xff0c;本地环境版本高&#xff0c;ssh不过去。正好最近对 腾讯出品的云原生 cnb 感兴趣&…...

浪潮交换机配置track检测实现高速公路收费网络主备切换NQA

浪潮交换机track配置 项目背景高速网络拓扑网络情况分析通信线路收费网络路由 收费汇聚交换机相应配置收费汇聚track配置 项目背景 在实施省内一条高速公路时遇到的需求&#xff0c;本次涉及的主要是收费汇聚交换机的配置&#xff0c;浪潮网络设备在高速项目很少&#xff0c;通…...

4. TypeScript 类型推断与类型组合

一、类型推断 (一) 什么是类型推断 TypeScript 的类型推断会根据变量、函数返回值、对象和数组的赋值和使用方式&#xff0c;自动确定它们的类型。 这一特性减少了显式类型注解的需要&#xff0c;在保持类型安全的同时简化了代码。通过分析上下文和初始值&#xff0c;TypeSc…...