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

chatgpt网站写个网页多少钱

chatgpt网站,写个网页多少钱,企业网站布局960,重庆哪家做网站好文章目录 1、过滤数据 filter()2、转换元素 map()3、排序 sorted()3.1、自定义排序规则 4、去重 distinct()5、限制元素数量 limit()6、收集结果 collect()6.1、收集为List6.2、收集为Set6.3、转为Map6.4、基本用法(注意键冲突会抛异常)6.5、处理键冲突&…

文章目录

  • 1、过滤数据 filter()
  • 2、转换元素 map()
  • 3、排序 sorted()
    • 3.1、自定义排序规则
  • 4、去重 distinct()
  • 5、限制元素数量 limit()
  • 6、收集结果 collect()
    • 6.1、收集为List
    • 6.2、收集为Set
    • 6.3、转为Map
    • 6.4、基本用法(注意键冲突会抛异常)
    • 6.5、处理键冲突(例如,取后出现的值)
    • 6.6、指定 Map 实现类
    • 6.7、将对象自身作为值
    • 6.8、统计总和
    • 6.9、字符串拼接
  • 7、遍历元素
  • 8、匹配检查
  • 9、分组 Grouping By
  • 10、聚合操作 reduce()
  • 11、统计
  • 12、跳过元素 skip()

1、过滤数据 filter()

List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);List<Integer> numberFilter = numbers.stream().filter(n -> n % 2 == 0) // 过滤偶数.collect(Collectors.toList()); // [2, 4]

2、转换元素 map()

List<String> words = Arrays.asList("apple", "banana");List<Integer> lengths = words.stream().map(String::length) // 转换为单词长度.collect(Collectors.toList()); // [5, 6]

3、排序 sorted()

List<String> list = Arrays.asList("a", "b", "c");List<String> sortedList = list.stream().sorted() // 自然排序(字典序).collect(Collectors.toList());// [a, b, c]

3.1、自定义排序规则

List<Integer> nums = Arrays.asList(3, 1, 4);List<Integer> customSorted = nums.stream().sorted((a, b) -> b - a) // 降序排序.collect(Collectors.toList()); // [4, 3, 1]

4、去重 distinct()

List<Integer> num2 = Arrays.asList(1, 2, 2, 3);List<Integer> unique = num2.stream().distinct() // 去重.collect(Collectors.toList()); // [1, 2, 3]

5、限制元素数量 limit()

List<Integer> number2 = Arrays.asList(1, 2, 3, 4, 5);List<Integer> firstThree = number2.stream().limit(3) // 取前3个元素.collect(Collectors.toList()); // [1, 2, 3]

6、收集结果 collect()

6.1、收集为List

List<String> list3 = Arrays.asList("a", "b", "ac", "d", "a", "c");List<String> filteredList = list3.stream().filter(s -> s.startsWith("a")).collect(Collectors.toList()); // 收集为List  过滤出以a开头的  [a, ac, a]

6.2、收集为Set

Set<String> set = list3.stream().collect(Collectors.toSet()); // 收集为Set  去重  [a, b, ac, c, d]

6.3、转为Map

Map<String, Integer> map = set.stream().collect(Collectors.toMap(s -> s, String::length)); // 转为Map   每个元素的长度  {a=1, ac=2, b=1, c=1, d=1}

6.4、基本用法(注意键冲突会抛异常)

实体类

@Data
public class Employee {//部门private String dept;//姓名private String name;//薪水private int salary;public Employee(String dept, String name) {this.dept = dept;this.name = name;}public Employee(String dept, String name, int salary) {this.dept = dept;this.name = name;this.salary = salary;}
}
List<Employee> employeeList = new ArrayList<>();
employeeList.add(new Employee("1", "张三", 6000));
employeeList.add(new Employee("2", "李四", 6000));
employeeList.add(new Employee("3", "王五", 6000));Map<String, Integer> map2 = employeeList.stream().collect(Collectors.toMap(Employee::getDept,   // 键的提取函数Employee::getSalary  // 值的提取函数)
);
//{1=6000, 2=6000, 3=6000}

6.5、处理键冲突(例如,取后出现的值)

通过第三个参数(合并函数)解决键冲突:

List<Employee> employeeList = new ArrayList<>();
employeeList.add(new Employee("1", "张三", 6000));
employeeList.add(new Employee("2", "李四", 6000));
employeeList.add(new Employee("3", "王五", 6000));
employeeList.add(new Employee("3", "赵六", 6000));Map<String, String> map3 = employeeList.stream().collect(Collectors.toMap(Employee::getDept,          // 键的提取函数Employee::getName,          // 值的提取函数(oldVal, newVal) -> newVal  // 解决冲突的函数(取新的value))
);
//{1=张三, 2=李四, 3=赵六}

6.6、指定 Map 实现类

/***  指定 Map 实现类*  通过第四个参数自定义 Map 类型(如 LinkedHashMap 保持插入顺序):*/
Map<String, String> idToName = employeeList.stream().collect(Collectors.toMap(Employee::getDept,Employee::getName,(oldVal, newVal) -> newVal,LinkedHashMap::new  // 指定Map实现));
//{1=张三, 2=李四, 3=赵六}

6.7、将对象自身作为值

/*** 将对象自身作为值   (注意键冲突会抛异常)* 使用  Function.identity()  直接引用元素作为值*/
List<Employee> employeeList222 = new ArrayList<>();
employeeList222.add(new Employee("1", "张三", 6000));
employeeList222.add(new Employee("2", "李四", 6000));
employeeList222.add(new Employee("3", "王五", 6000));
Map<String, Employee> idToPerson = employeeList222.stream().collect(Collectors.toMap(Employee::getDept,Function.identity()  // 值=对象本身));
// {
// 1=Employee(dept=1, name=张三, salary=6000),
// 2=Employee(dept=2, name=李四, salary=6000),
// 3=Employee(dept=3, name=王五, salary=6000)
// }

6.8、统计总和

例如部门工资总和

List<Employee> employeeList333 = new ArrayList<>();
employeeList333.add(new Employee("1", "张三", 6000));
employeeList333.add(new Employee("2", "李四", 6000));
employeeList333.add(new Employee("3", "王五", 6000));
employeeList333.add(new Employee("1", "张三1", 7000));
employeeList333.add(new Employee("2", "李四1", 8000));
employeeList333.add(new Employee("3", "王五1", 9000));
Map<String, Integer> deptSalarySum = employeeList333.stream().collect(Collectors.toMap(Employee::getDept,Employee::getSalary,Integer::sum  // 合并时累加工资));
//{1=13000, 2=14000, 3=15000}

6.9、字符串拼接

/**  字符串拼接  */
List<String> str = Arrays.asList("a", "b", "c");
String join1 = str.stream().collect(Collectors.joining());  //abc
String join2 = str.stream().collect(Collectors.joining(", "));  //a, b, c
String join3 = str.stream().collect(Collectors.joining(", ", "[", "]"));    //[a, b, c]

7、遍历元素

List<String> list3 = Arrays.asList("a", "b", "ac", "d", "a", "c");
list3.stream().forEach(System.out::println); // 打印每个元素

8、匹配检查

/***  匹配检查: anyMatch()   allMatch()   noneMatch()*/List<String> list4 = Arrays.asList("a", "b", "c");
boolean hasA = list4.stream().anyMatch(s -> s.contains("a")); // 是否存在包含"a"的元素  trueList<Integer> numbers4 = Arrays.asList(1, 2, 3, 4, 5);
boolean allPositive = numbers4.stream().allMatch(n -> n > 0); // 是否所有元素都大于0     true

9、分组 Grouping By

List<Employee> employees = new ArrayList<>();
employees.add(new Employee("1","张三", 5000));
employees.add(new Employee("1","李四", 5500));
employees.add(new Employee("2","王五", 6000));
employees.add(new Employee("2","赵六", 7000));
employees.add(new Employee("3","韩七", 5800));
employees.add(new Employee("4","魏八", 9000));// 按属性分组(按照部门分组)
Map<String, List<Employee>> groupByDept = employees.stream().collect(Collectors.groupingBy(Employee::getDept));
// {
// 1=[Employee(dept=1, name=张三, salary=5000), Employee(dept=1, name=李四, salary=5500)],
// 2=[Employee(dept=2, name=王五, salary=6000), Employee(dept=2, name=赵六, salary=4000)],
// 3=[Employee(dept=3, name=韩七, salary=5800)],
// 4=[Employee(dept=4, name=魏八, salary=9000)]
// }// 分组后对值进一步处理(如求数量:统计每个部门的人数)
Map<String, Long> countByDept = employees.stream().collect(Collectors.groupingBy(Employee::getDept, Collectors.counting()));
//{1=2, 2=2, 3=1, 4=1}// 多级分组(嵌套分组) 先按照每个部门分组,然后按照薪水是否超过5000分组
Map<String, Map<Boolean, List<Employee>>> multiGroup = employees.stream().collect(Collectors.groupingBy(Employee::getDept,Collectors.groupingBy(e -> e.getSalary() > 5000)));
// {
// 1={false=[Employee(dept=1, name=张三, salary=5000)], true=[Employee(dept=1, name=李四, salary=5500)]},
// 2={true=[Employee(dept=2, name=王五, salary=6000), Employee(dept=2, name=赵六, salary=7000)]},
// 3={true=[Employee(dept=3, name=韩七, salary=5800)]},
// 4={true=[Employee(dept=4, name=魏八, salary=9000)]}
// }

10、聚合操作 reduce()

List<Integer> numbers5 = Arrays.asList(1, 2, 3, 4, 5);
Optional<Integer> sum = numbers5.stream().reduce((a, b) -> a + b); // 求和(返回Optional)   Optional[15]int total = numbers5.stream().reduce(0, Integer::sum); // 初始值为0的求和   15

11、统计

/*** 统计: count()   min()   max()*/List<String> list5 = Arrays.asList("a", "b", "c");
long count = list5.stream().count(); // 元素总数  3List<Integer> numbers6 = Arrays.asList(1, 2, 3, 4, 5);
Optional<Integer> max = numbers6.stream().max(Integer::compare); // 最大值  Optional[5]
Optional<Integer> min = numbers6.stream().min(Integer::compare); // 最小值  Optional[1]

12、跳过元素 skip()

List<Integer> numbers7 = Arrays.asList(1, 2, 3, 4, 5);
List<Integer> skipped = numbers7.stream().skip(2) // 跳过前2个元素.collect(Collectors.toList()); //[3, 4, 5]

文章转载自:

http://LEKbryGa.tkyxL.cn
http://CdMkCDwl.tkyxL.cn
http://rGj9GBtH.tkyxL.cn
http://klOIn7ZI.tkyxL.cn
http://YR6kkh9B.tkyxL.cn
http://XIIbTVEt.tkyxL.cn
http://838WPM9D.tkyxL.cn
http://mGK7P6lD.tkyxL.cn
http://DErWckUL.tkyxL.cn
http://i05OBDzC.tkyxL.cn
http://g1fuBgZB.tkyxL.cn
http://T5k9gbf9.tkyxL.cn
http://0ojE9J6C.tkyxL.cn
http://xcrXOOoF.tkyxL.cn
http://HdUc5BrK.tkyxL.cn
http://uRt8leFl.tkyxL.cn
http://TA5vUc1v.tkyxL.cn
http://w5mLIl1m.tkyxL.cn
http://8AS8h8QR.tkyxL.cn
http://Wzrr7YZs.tkyxL.cn
http://AAsptIVy.tkyxL.cn
http://wcEdgzbj.tkyxL.cn
http://eqDFrQPN.tkyxL.cn
http://wYziU9AL.tkyxL.cn
http://EvqrubSg.tkyxL.cn
http://OfcMyrpf.tkyxL.cn
http://pBh2iojU.tkyxL.cn
http://Mt5wpAMX.tkyxL.cn
http://5o7uRDxk.tkyxL.cn
http://dvWaKIrp.tkyxL.cn
http://www.dtcms.com/wzjs/692124.html

相关文章:

  • 建设银行官方招聘网站新蔡县城乡建设局网站
  • 理财网站模板免费下载北京装修公司前十强
  • 邯郸网站建设产品介绍廊坊网站群发关键词
  • 怎样看网站建设制作方为什么上不了建设银行个人网站
  • 做爰试看的网站无锡网站建设服务公司
  • 在什么文件中加入什么代码告诉搜索引擎蜘蛛网站地图的文件位置?微信外链网站开发
  • 建e网3d模型库一个空间两个网站对seo
  • 潍坊网站关键字优化公共营养师报考条件
  • 网站制作职业网页模板下载
  • 如何做销售网站网站开发专业能力
  • 上海手机网站建设电话杭州观建设计网站
  • 网站正在紧急建设中在线网站制作系统源码
  • 海南房产网站制作wordpress小鹅通
  • 做网站公违法嘛做网站要多少
  • 花都建网站公司网站开发者取色工具
  • php网站开发专业xiu主题做的网站
  • 韩国男女直接做的视频网站微商手机网站制作公司哪家好
  • 个人网站开发主要问题对互联网网站的理解
  • 网站建设需要摊销几年白银网站建设熊掌号
  • 旅游电子商务网站开发方案云和建设局网站
  • 做网站 传视频 用什么笔记本好沈阳城市建设学院网站
  • 全校网站建设与管理查看网站是用什么做的
  • 做网站公司深圳建公司网站
  • 白酒企业网站源码公司注册地址和经营地址不一致
  • 网站 开发 工具wordpress加载进度条
  • 淘宝客商品推广网站建设淘宝卖东西如何在网站做宣传
  • 网站设计建设公司教程公司网站优化
  • 网站申请服务器空间网站后台账户密码
  • 销售网站建设工资多少西部数码域名注册官网
  • 兰州网站备案谁家做天津做网站价格