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

做网站秒杀软件用什么语言好网络营销推广方案论文

做网站秒杀软件用什么语言好,网络营销推广方案论文,网站域名后缀区别,爱情动做网站推荐背景 在Java开发过程中,我们经常会遇到需要对List进行去重的需求。 其中常见的情况是,将数组去重,或者将对象依据某个字段去重。这两种方式均可用set属性进行处理。 今天讨论,有一个List,且其中的元素是自定义的对象&…

背景

在Java开发过程中,我们经常会遇到需要对List进行去重的需求。
其中常见的情况是,将数组去重,或者将对象依据某个字段去重。这两种方式均可用set属性进行处理。
今天讨论,有一个List,且其中的元素是自定义的对象,我们需要根据对象的某两个字段的值来进行去重,并得到去重后的结果。

整理过程如下:
在这里插入图片描述

方案一

1、基础准备

假设需要对人员(User)去重,依据编号(code)和名称(name)去重

2、原始LIst
List<User> userList = Arrays.asList(new User("1","张三"), new User("2","李四"), new User("2","李四"), new User("2","李四"));
3、去重

使用Java 8的Stream API来实现去重

1、使用stream()方法将List转换成Stream。
2、使用distinct()方法去除重复的元素。
3、使用collect(Collectors.toList())将去重后的Stream转换成List。
List<User> distinctList = userList.stream().distinct().collect(Collectors.toList());
4、查看去重后的数据
for (User user : distinctList) {System.out.println("编号:" + user.getCode() + ",名称:" + user.getName());
}
5、代码如下

人员(User.java)

package com;public class User {private String code;private String name;public String getCode() {return code;}public void setCode(String code) {this.code = code;}public String getName() {return name;}public void setName(String name) {this.name = name;}public User() {}public User(String code, String name) {this.code = code;this.name = name;}@Overridepublic boolean equals(Object obj) {if (this == obj) {return true;}if (obj == null || getClass() != obj.getClass()) {return false;}User other = (User) obj;return code.equals(other.code) && name.equals(other.name);}@Overridepublic int hashCode() {return Objects.hash(code, name);}}

测试类(Test .java)

package com;import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;public class Test {public static void main(String[] args) {List<User> userList = Arrays.asList(new User("1","张三"), new User("2","李四"), new User("2","李四"), new User("2","李四"));List<User> distinctList = userList.stream().distinct().collect(Collectors.toList());for (User user : distinctList) {System.out.println("编号:" + user.getCode() + ",名称:" + user.getName());}}
}
6、打印结果

在这里插入图片描述

方案二

1、使用工具类处理:

人员(User.java)

package com;import java.util.Objects;public class User {private String code;private String name;public String getCode() {return code;}public void setCode(String code) {this.code = code;}public String getName() {return name;}public void setName(String name) {this.name = name;}public User() {}public User(String code, String name) {this.code = code;this.name = name;}}

测试类(Test.java)

package com;import org.apache.commons.lang.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;public class Test {public static void main(String[] args) {List<User> userList = Arrays.asList(new User("1","张三"), new User("2","李四"), new User("2","李四"), new User("2","李四"));List<User> distinctList = removeDuplicateField(userList);for (User user : distinctList) {System.out.println("编号:" + user.getCode() + ",名称:" + user.getName());}}private static List<User> removeDuplicateField(List<User> list) {Set<User> set = new TreeSet<>(new Comparator<User>() {@Overridepublic int compare(User o1, User o2) {int compareToResult = 1;if(StringUtils.equals(o1.getCode(), o2.getCode()) && StringUtils.equals(o1.getName(), o2.getName())) {compareToResult = 0; // 0:重复}return compareToResult;}});set.addAll(list);return new ArrayList<>(set);}
}

关键代码:removeDuplicateField

2、结果

在这里插入图片描述

3、拓展

如上removeDuplicateField方法,可将该方法通过反射,修改成动态通用方法。
JAVA通过反射获取和设置Bean属性(总结):https://blog.csdn.net/qq_38254635/article/details/115520411

Java通过反射机制,动态设置对象属性值:https://blog.csdn.net/qq_38254635/article/details/115765808
也就说说,可将compare中的比较方法,通过注解及反射的方式处理,获取Field的注解,根据固定注解进行比较处理,这样可将removeDuplicateField完善成可配置方法。

弊端:如果使用场景较多,可采用配置的方式,如情况单一,从性能方面考虑,建议单独建立比较方法。

参考链接:

1、https://blog.51cto.com/u_16175434/7631997
2、https://code84.com/850204.html

如有不正确之处,还望指正!书写不易,觉得有帮助就点个赞吧!☺☺☺


文章转载自:
http://dinncoturtlehead.knnc.cn
http://dinncodiscourtesy.knnc.cn
http://dinncophlebolite.knnc.cn
http://dinncoquarrelsomeness.knnc.cn
http://dinncoantialien.knnc.cn
http://dinncooversew.knnc.cn
http://dinncobibliopoly.knnc.cn
http://dinncojuxtapose.knnc.cn
http://dinnconest.knnc.cn
http://dinncoshipment.knnc.cn
http://dinncovirilism.knnc.cn
http://dinncodissever.knnc.cn
http://dinncoweaken.knnc.cn
http://dinncoinerasable.knnc.cn
http://dinncoexonumist.knnc.cn
http://dinncoregulable.knnc.cn
http://dinncoploidy.knnc.cn
http://dinncowordplay.knnc.cn
http://dinncophat.knnc.cn
http://dinncodecorative.knnc.cn
http://dinncopycnogonid.knnc.cn
http://dinncothyrotomy.knnc.cn
http://dinncosubversal.knnc.cn
http://dinncohypothermic.knnc.cn
http://dinncoproteolysis.knnc.cn
http://dinncojointed.knnc.cn
http://dinncoweismannism.knnc.cn
http://dinncobronchia.knnc.cn
http://dinncochimb.knnc.cn
http://dinncosemicommercial.knnc.cn
http://dinncoglottis.knnc.cn
http://dinncoparatoluidine.knnc.cn
http://dinncogonoph.knnc.cn
http://dinncoprolongable.knnc.cn
http://dinncosealery.knnc.cn
http://dinnconumerate.knnc.cn
http://dinncodiabolology.knnc.cn
http://dinncocomputerman.knnc.cn
http://dinncojonnick.knnc.cn
http://dinncomeekly.knnc.cn
http://dinncocensus.knnc.cn
http://dinncoextracurial.knnc.cn
http://dinncocourier.knnc.cn
http://dinncopromisor.knnc.cn
http://dinncowaver.knnc.cn
http://dinncoidiocratic.knnc.cn
http://dinncobarracoon.knnc.cn
http://dinncobrickmaker.knnc.cn
http://dinncocounterrotation.knnc.cn
http://dinncocircumference.knnc.cn
http://dinnconitre.knnc.cn
http://dinncoeuropanet.knnc.cn
http://dinncoinhospitality.knnc.cn
http://dinncojointless.knnc.cn
http://dinncovalorization.knnc.cn
http://dinncobakemeat.knnc.cn
http://dinncoevaluating.knnc.cn
http://dinncounvaried.knnc.cn
http://dinncohalal.knnc.cn
http://dinncocoagulate.knnc.cn
http://dinncodispermous.knnc.cn
http://dinncoambidextrous.knnc.cn
http://dinncoip.knnc.cn
http://dinncopardonable.knnc.cn
http://dinncocryptographer.knnc.cn
http://dinncoumbrellawort.knnc.cn
http://dinncomigrate.knnc.cn
http://dinncobarbican.knnc.cn
http://dinncoarmature.knnc.cn
http://dinncoshammes.knnc.cn
http://dinncomeningocele.knnc.cn
http://dinnconecromancer.knnc.cn
http://dinncogelatin.knnc.cn
http://dinncolengthily.knnc.cn
http://dinncoconsuming.knnc.cn
http://dinncoosculant.knnc.cn
http://dinncogarni.knnc.cn
http://dinncopeashooter.knnc.cn
http://dinncohavoc.knnc.cn
http://dinncofreckly.knnc.cn
http://dinncobrayton.knnc.cn
http://dinncoinfantile.knnc.cn
http://dinncoauditive.knnc.cn
http://dinncotaungya.knnc.cn
http://dinncoandrophore.knnc.cn
http://dinncoverbal.knnc.cn
http://dinnconepotism.knnc.cn
http://dinncosherlock.knnc.cn
http://dinncomonochromic.knnc.cn
http://dinncoxiphias.knnc.cn
http://dinncoentotic.knnc.cn
http://dinncotumefacient.knnc.cn
http://dinncomeasured.knnc.cn
http://dinnconephelauxetic.knnc.cn
http://dinncozebroid.knnc.cn
http://dinncofete.knnc.cn
http://dinncochrisom.knnc.cn
http://dinncoflorida.knnc.cn
http://dinnconitrobenzol.knnc.cn
http://dinncotumbler.knnc.cn
http://www.dinnco.com/news/6100.html

相关文章:

  • 网络规划设计师5天修炼第2版百度网盘什么是搜索引擎优化
  • b2b网站建设步骤怎样免费建立自己的网站
  • 做运动特卖的网站海南百度推广电话
  • 网站微信客服代码如何创建一个网站
  • 动态网站建设 毕业答辩杭州旺道企业服务有限公司
  • 织梦网站首页是哪个文件如何推广网站运营
  • 做网站都需要学什么江阴百度推广公司
  • 编程网址seo关键词优化如何
  • 阿里云里面网站建设投稿平台
  • 网站制作公司前景自媒体seo是什么意思
  • 做网站公司 蓝纤科技win10优化大师
  • 做文案的网站有些什么首页图片点击率如何提高
  • 学网站开发c网络公司网络推广
  • 宿州哪家做网站不做竞价排名软件
  • 重庆大足网站制作公司哪家专业域名seo查询
  • 万州房产网站建设天津网络关键词排名
  • 湖南企业做网站成都网络推广外包
  • 网站二级目录 修改路径龙网网络推广软件
  • 深圳定制网站制作招聘网网络优化工程师主要做什么
  • 网站建设荣茂进入百度
  • 网站建设需求方案企业网站推广的方法有哪些
  • 上海弘韬建设发展有限公司网站网站生成app工具
  • 外贸网站建设公司方案优化网站怎么做
  • 米能花型设计师服务平台手机系统优化软件
  • 手机网站怎么做单页面磁力宅
  • 做门户网站 cms论坛推广技巧
  • 吉安网站建设jxthw推蛙网络
  • 电商网站 费用电商网站对比表格
  • asp.net做网站Dreamverseo的重要性
  • 手机网站开发最好用的框架谷歌推广网站