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

桂林网站制作人才招聘新手运营从哪开始学

桂林网站制作人才招聘,新手运营从哪开始学,北京制卡厂家做卡公司北京制卡网站_北京制卡_北京 去114网,WordPress采集淘宝头条插件文章目录 前言正文数据对象1. 对象整体去重2. 单个属性去重(只返回属性)3. 单个属性去重4. 多个属性去重验证方法运行结果 结尾 前言 对于list集合进行去重操作,多种情况进行记录. 只记录在学习与实践过程中需要对集合操作的场景,方便下次能够直接快速的回忆起来. 当然这些方…

文章目录

      • 前言
      • 正文
        • 数据对象
        • 1. 对象整体去重
        • 2. 单个属性去重(只返回属性)
        • 3. 单个属性去重
        • 4. 多个属性去重
        • 验证方法
        • 运行结果
      • 结尾

前言

对于list集合进行去重操作,多种情况进行记录.

只记录在学习与实践过程中需要对集合操作的场景,方便下次能够直接快速的回忆起来.

当然这些方法的使用与操作皆是对于Java8stream操作,TreeSet不重复特性进行的运用.

如果能够更好更快的达成目的,也是不必拘泥于某一些固定的方式去处理数据,以效率与程序开销优先.

正文

数据对象

将数据对象写成静态不可变的list来方便我们对于程序进行调用验证

private static final List<SyncBalance> list = asList(new SyncBalance(BigDecimal.ZERO, "12345678", 0, 1, "GGBond", 32, 0),new SyncBalance(BigDecimal.ZERO, "22345678", 0, 1, "GGBond", 32, 0),new SyncBalance(BigDecimal.ZERO, "22345678", 1, 1, "GGBond", 32, 0),new SyncBalance(BigDecimal.ZERO, "22345678", 1, 1, "GGBond", 32, 0)
);
1. 对象整体去重
/*** 1. 对所有属性一样的数据进行去重*/
public static void allColumnDistinct() {List<SyncBalance> allColumnDistinct = list.stream().distinct().collect(Collectors.toList());
}
2. 单个属性去重(只返回属性)
/*** 2. 对单个属性去重,只返回去重的属性*/
public static void columnDistinct() {List<String> columnDistinct = list.stream().map(SyncBalance::getMobile).distinct().collect(Collectors.toList());
}
3. 单个属性去重
/*** 3-1. 对单个属性一样的数据进行去重,下面是对`mobile`去重*/
public static void oneColumnDistinctMethodOne() {List<SyncBalance> oneColumnDistinctMethodOne = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(SyncBalance::getMobile))), ArrayList::new));
}
/*** 3-2. 对单个属性一样的数据进行去重,下面是对`mobile`去重(通过自定义属性去重方法)*/
public static void oneColumnDistinctMethodTwo() {List<SyncBalance> oneColumnDistinctMethodTwo = list.stream().filter(distinctByKey(i -> i.getMobile())).collect(Collectors.toList());
}/**
* list对象单个个字段去重(自定义属性)
* @param keyExtractor 去重的对象字段
* @return
* @param <T>
*/
public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {Map<Object, Boolean> seen = new ConcurrentHashMap<>();return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}
/*** 3-3. 对单个属性一样的数据进行去重,下面是对`mobile`去重* 利用TreeSet进行去重*/
public static void oneColumnDistinctMethodThree() {TreeSet<SyncBalance> oneColumnDistinctMethodThree = new TreeSet<>(Comparator.comparing(i -> i.getMobile()));list.forEach(a -> oneColumnDistinctMethodThree.add(a));
}
4. 多个属性去重
/*** 4. 多个字段条件去重*/
public static void twoColumnDistinct() {List<SyncBalance> twoColumnDistinct = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(p -> p.getMobile() + ";" + p.getStatus()))), ArrayList::new));
}
验证方法

对于验证方法添加了一些分隔的数据

/*** 验证的main方法* @param args*/
public static void main(String[] args) {allColumnDistinct();columnDistinct();oneColumnDistinctMethodOne();oneColumnDistinctMethodTwo();oneColumnDistinctMethodThree();twoColumnDistinct();
}
运行结果
allColumnDistinct---v
SyncBalance(accountBalance=0, mobile=12345678, status=0, sysId=1, loginAccountName=GGBond, keepOrUpdate=32, id=0)
SyncBalance(accountBalance=0, mobile=22345678, status=0, sysId=1, loginAccountName=GGBond, keepOrUpdate=32, id=0)
SyncBalance(accountBalance=0, mobile=22345678, status=1, sysId=1, loginAccountName=GGBond, keepOrUpdate=32, id=0)
allColumnDistinct---^
columnDistinct---v
12345678
22345678
columnDistinct---^
oneColumnDistinctMethodOne---v
SyncBalance(accountBalance=0, mobile=12345678, status=0, sysId=1, loginAccountName=GGBond, keepOrUpdate=32, id=0)
SyncBalance(accountBalance=0, mobile=22345678, status=0, sysId=1, loginAccountName=GGBond, keepOrUpdate=32, id=0)
oneColumnDistinctMethodOne---^
oneColumnDistinctMethodTwo---v
SyncBalance(accountBalance=0, mobile=12345678, status=0, sysId=1, loginAccountName=GGBond, keepOrUpdate=32, id=0)
SyncBalance(accountBalance=0, mobile=22345678, status=0, sysId=1, loginAccountName=GGBond, keepOrUpdate=32, id=0)
oneColumnDistinctMethodTwo---^
oneColumnDistinctMethodThree---v
SyncBalance(accountBalance=0, mobile=12345678, status=0, sysId=1, loginAccountName=GGBond, keepOrUpdate=32, id=0)
SyncBalance(accountBalance=0, mobile=22345678, status=0, sysId=1, loginAccountName=GGBond, keepOrUpdate=32, id=0)
oneColumnDistinctMethodThree---^
twoColumnDistinct---v
SyncBalance(accountBalance=0, mobile=12345678, status=0, sysId=1, loginAccountName=GGBond, keepOrUpdate=32, id=0)
SyncBalance(accountBalance=0, mobile=22345678, status=0, sysId=1, loginAccountName=GGBond, keepOrUpdate=32, id=0)
SyncBalance(accountBalance=0, mobile=22345678, status=1, sysId=1, loginAccountName=GGBond, keepOrUpdate=32, id=0)
twoColumnDistinct---^

image-20240518151444939

结尾

集合的操作不止拘泥于stream流TreeSet可以处理,其他一下如果可以实现皆可使用.

以上,皆可直接使用.


文章转载自:

http://38jXJ6fP.dLjny.cn
http://MAB94bjY.dLjny.cn
http://xqKw0AEP.dLjny.cn
http://rVYUPsfc.dLjny.cn
http://Qk204L9L.dLjny.cn
http://gXvShN9F.dLjny.cn
http://CaUv330g.dLjny.cn
http://H3XaRSDD.dLjny.cn
http://VrN9oR7n.dLjny.cn
http://q7iWxAVt.dLjny.cn
http://SnHqBCw0.dLjny.cn
http://Ftfzui7U.dLjny.cn
http://f2CLZA5n.dLjny.cn
http://BFAeK3St.dLjny.cn
http://UChepCpF.dLjny.cn
http://G8VB04ql.dLjny.cn
http://9WsEv288.dLjny.cn
http://iRaaCrNZ.dLjny.cn
http://n1CvLJSO.dLjny.cn
http://svDX7xtR.dLjny.cn
http://eQpXOziZ.dLjny.cn
http://kkou8Ccz.dLjny.cn
http://4Oa7t8F2.dLjny.cn
http://HuPY7rYc.dLjny.cn
http://6Bv11ONl.dLjny.cn
http://jxvqN0bM.dLjny.cn
http://q1yVST83.dLjny.cn
http://WK4Z4RSG.dLjny.cn
http://GAnw2GwP.dLjny.cn
http://KBhjqQmY.dLjny.cn
http://www.dtcms.com/wzjs/729364.html

相关文章:

  • 个人网站制作软件公众号文章怎么添加小程序
  • html5可不可以建设手机网站福建省建设质量安全协会网站
  • 怎么在网站添加关键词开一个网站多少钱
  • 邢台市住房和城乡建设局网站帮别人做违法网站
  • 室内设计联盟电脑版网站建设优化服务精英
  • 创建网站英文在上海哪个网站比较好
  • 计算机做网站难吗企业网站打包下载
  • php wap网站实现滑动式数据分页网站色调选择
  • 国外域名。国内网站适合小企业的erp软件
  • 外贸网站vps服务器哪个网站可以找设计师做设计
  • 手机网站制作费wordpress ios版
  • 如何布置网站阳江企业网站排名优化
  • iis7.5 发布网站wordpress 煎蛋网插件
  • 网站建设优化推广杭州拓者设计吧网站
  • 网站建设与实践心得体会全国十大电商排名
  • 网站做推广需要营业执照网站开发技术视频
  • 铁岭做网站网站建设所有软件清单
  • wordpress房屋网站模板自己开的网站 可以做代销吗
  • 做网站需要什么资金广州站八个字
  • 卡盟网站怎么做做机器学习比赛的网站
  • 提供网站建设定制整合营销传播经典案例
  • 自己做网站可以随便起名字吗wordpress 自媒体
  • 自贡建设投资有限公司网站做美食的网站可以放些小图片
  • 为什么无法登录建设银行网站网站模板文件怎么下载
  • 中医院网站源码海外求购信息网
  • 智能网站建设步骤小程序微信开发
  • 做电商的进货网站百货店怎么做网站送货
  • 遨游网站建设有限公司推广链接点击器app
  • 校园网站建设重要性广州燃气集团有限公司
  • 中国做机床的公司网站成全视频免费观看在线看第7季高清