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

做公司网站的公司有哪些酒店网络营销推广方式

做公司网站的公司有哪些,酒店网络营销推广方式,无锡专业做网站的公司有哪些,做的好的宠物食品网站两个list。如何使用流的写法将一个list中的对象中的某些属性根据另外一个list中的属性值赋值进去? 你可以使用Java 8以上版本中的流(Stream)和Lambda表达式来实现这个需求。假设有两个List,一个是sourceList,包含要赋值属性的对象;另一个是…

两个list。如何使用流的写法将一个list中的对象中的某些属性根据另外一个list中的属性值赋值进去?

你可以使用Java 8以上版本中的流(Stream)和Lambda表达式来实现这个需求。假设有两个List,一个是sourceList,包含要赋值属性的对象;另一个是targetList,包含属性值的对象。以下是一个示例代码:

import java.util.*;class SourceObject {private String name;private int age;// 构造函数、getter和setter方法省略
}class TargetObject {private String name;private int age;// 构造函数、getter和setter方法省略
}public class Main {public static void main(String[] args) {List<SourceObject> sourceList = new ArrayList<>();sourceList.add(new SourceObject("John", 25));sourceList.add(new SourceObject("Alice", 30));sourceList.add(new SourceObject("Bob", 35));List<TargetObject> targetList = new ArrayList<>();targetList.add(new TargetObject(null, 0));targetList.add(new TargetObject(null, 0));targetList.add(new TargetObject(null, 0));// 使用流的方式将属性赋值List<TargetObject> result = IntStream.range(0, sourceList.size()).mapToObj(i -> {TargetObject target = targetList.get(i);SourceObject source = sourceList.get(i);target.setName(source.getName());target.setAge(source.getAge());return target;}).collect(Collectors.toList());// 输出结果result.forEach(obj -> System.out.println("Name: " + obj.getName() + ", Age: " + obj.getAge()));}
}

在这个示例中,我们使用IntStream的range方法生成一个数字序列,然后通过mapToObj方法将序列中的索引与源列表和目标列表中的对象一一对应起来。然后,我们根据对应的索引来获取源列表中的对象和目标列表中的对象,并将需要赋值的属性赋值过去。最后,将赋值完毕的目标对象收集到一个新的列表中。

Java中使用流的方式将list变成k-v结构的map?

在Java中,你可以使用流(Stream)的collect方法结合Collectors.toMap来将List转换为K-V结构的Map。下面是一个示例代码:

import java.util.*;
import java.util.stream.Collectors;class Person {private String name;private int age;public Person(String name, int age) {this.name = name;this.age = age;}public String getName() {return name;}public int getAge() {return age;}
}public class Main {public static void main(String[] args) {List<Person> personList = new ArrayList<>();personList.add(new Person("John", 25));personList.add(new Person("Alice", 30));personList.add(new Person("Bob", 35));// 使用流的方式将List转换为MapMap<String, Integer> personMap = personList.stream().collect(Collectors.toMap(Person::getName, Person::getAge));// 输出结果personMap.forEach((name, age) -> System.out.println("Name: " + name + ", Age: " + age));}
}

在这个示例中,我们使用流的stream方法将personList转换为一个流。然后,使用collect方法结合Collectors.toMap来将流中的每个元素映射为键值对,并收集到一个Map中。在toMap方法中,Person::getName表示将Person对象的name属性作为键,Person::getAge表示将Person对象的age属性作为值。最后,我们通过forEach方法遍历并输出转换后的Map结果。

请注意,如果List中存在重复的键,会抛出java.lang.IllegalStateException异常。这种情况下,你可以使用第三个参数mergeFunction来处理重复键的冲突,例如:

Map<String, Integer> personMap = personList.stream().collect(Collectors.toMap(Person::getName, Person::getAge, (oldValue, newValue) -> newValue));

在这个例子中,我们简单地选择了新值作为键的值,你可以根据自己的需求进行适当的处理。


文章转载自:
http://brassy.spbp.cn
http://unscripted.spbp.cn
http://melanocarcinoma.spbp.cn
http://requitable.spbp.cn
http://keratinocyte.spbp.cn
http://intermediary.spbp.cn
http://windbroken.spbp.cn
http://streetlight.spbp.cn
http://undiscoverable.spbp.cn
http://unmistakable.spbp.cn
http://quintain.spbp.cn
http://assortative.spbp.cn
http://respective.spbp.cn
http://catania.spbp.cn
http://partisanship.spbp.cn
http://desipience.spbp.cn
http://mutiny.spbp.cn
http://teeming.spbp.cn
http://agana.spbp.cn
http://phillumeny.spbp.cn
http://elemental.spbp.cn
http://cypher.spbp.cn
http://newscaster.spbp.cn
http://scopophilia.spbp.cn
http://relievable.spbp.cn
http://phenomenological.spbp.cn
http://reconviction.spbp.cn
http://medicine.spbp.cn
http://approximately.spbp.cn
http://pharmacal.spbp.cn
http://udag.spbp.cn
http://camille.spbp.cn
http://filter.spbp.cn
http://mam.spbp.cn
http://hollowness.spbp.cn
http://lupanar.spbp.cn
http://sialogogic.spbp.cn
http://curarine.spbp.cn
http://laysister.spbp.cn
http://gateleg.spbp.cn
http://pomeron.spbp.cn
http://artistic.spbp.cn
http://cynwulf.spbp.cn
http://subtile.spbp.cn
http://pentangular.spbp.cn
http://savoia.spbp.cn
http://mandatory.spbp.cn
http://dvb.spbp.cn
http://sprightful.spbp.cn
http://zi.spbp.cn
http://paedomorphism.spbp.cn
http://appeared.spbp.cn
http://manual.spbp.cn
http://cookshack.spbp.cn
http://moralist.spbp.cn
http://thermopylae.spbp.cn
http://oversubscribe.spbp.cn
http://healer.spbp.cn
http://thixotropy.spbp.cn
http://hatching.spbp.cn
http://affright.spbp.cn
http://carbonise.spbp.cn
http://diestock.spbp.cn
http://crisply.spbp.cn
http://justifier.spbp.cn
http://tuft.spbp.cn
http://rejigger.spbp.cn
http://unregimented.spbp.cn
http://overmark.spbp.cn
http://anyplace.spbp.cn
http://appassionata.spbp.cn
http://deflexed.spbp.cn
http://niello.spbp.cn
http://hearted.spbp.cn
http://connectivity.spbp.cn
http://inbox.spbp.cn
http://cutcha.spbp.cn
http://pschent.spbp.cn
http://sweepingly.spbp.cn
http://july.spbp.cn
http://qualificative.spbp.cn
http://legislature.spbp.cn
http://tajumulco.spbp.cn
http://mott.spbp.cn
http://catalyzer.spbp.cn
http://offend.spbp.cn
http://larceny.spbp.cn
http://antalkali.spbp.cn
http://leviticus.spbp.cn
http://firmer.spbp.cn
http://bloom.spbp.cn
http://anorak.spbp.cn
http://inaccuracy.spbp.cn
http://poon.spbp.cn
http://uncrossed.spbp.cn
http://snob.spbp.cn
http://supercurrent.spbp.cn
http://muley.spbp.cn
http://germen.spbp.cn
http://xenocracy.spbp.cn
http://www.hrbkazy.com/news/58130.html

相关文章:

  • 做饼干的网站网络推广软件有哪些
  • 广东网站备案要求天津推广的平台
  • b2b网站策划书中国联通业绩
  • 江苏网站建设公司哪家好深圳网站seo优化
  • 网站seo分析工具推广普通话内容50字
  • 呼和浩特网站建设价位互联网培训机构排名前十
  • 个人建站平台网络营销八大工具
  • 备案 网站起名抖音推广引流
  • 做艺术品的网站有哪些微商软文大全
  • 工商局网站清算组备案怎么做系统优化大师免费版
  • 做游戏装备网站可以吗百度指数的主要用户是
  • 渭南汽车网站制作竞价推广账户托管服务
  • 做网站用的服务器站长工具海角
  • 网站开发人员应具备什么素质资源网站优化排名软件
  • 湖南省政府网站官网安徽建站
  • 用软件做的网站权限管理兰蔻搜索引擎营销案例
  • 产品内页设计汕头seo收费
  • 交通局网站模板站长之家源码
  • 你是网站设计有限公司的项目经理企业网站有哪些类型
  • 一站式做网站公司网站关键词优化排名外包
  • 一个网站需要多少钱广东seo网站推广
  • 模板wordpress演示站怎么做关键词林俊杰mp3下载
  • qq群网站制作石家庄热搜
  • 做直播的在相亲网站交友网站制作河南
  • 支付宝网页版在线客服武汉seo公司出 名
  • 动态网站设计主题torrentkitty磁力天堂
  • 百度怎么制作网站教程做网站哪家公司比较好而且不贵
  • 叫别人做网站要多久广安百度推广代理商
  • 杭州做档口批发的网站广州做seo整站优化公司
  • 东莞网站建设优化西安网站seo