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

软件开发招标网站百度怎么精准搜索

软件开发招标网站,百度怎么精准搜索,重庆建站模板源码,品牌网站开发文章目录 前言正文数据对象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://www.dtcms.com/wzjs/427967.html

相关文章:

  • 做网站需要什么部门批准高端快速建站
  • 做网站用html5上海专业seo公司
  • 建立网站怎么做关键字昆明新闻头条最新消息
  • 北京公司模板网站好t和p在一起怎么做网站
  • 秦皇岛企业建设网站天津百度推广网络科技公司
  • 家纺网站建设免费的网站
  • 云南省植保植检站网址永久免费的电销外呼系统
  • 即墨做网站的网页设计网站建设
  • 温江做网站的公司宁波核心关键词seo收费
  • 企业网络安全管理制度和应急预案福建seo排名
  • 自己建商城型网站怎样做网站
  • 第一次做网站合肥360seo排名
  • 网站开发日志模板教育培训加盟
  • 大连网站排名公司手机怎么制作网站
  • 青岛网站域名备案代刷网站推广链接0元价格
  • ps软件手机版下载优化网站广告优化
  • 2018年企业网站优化如何做互联网营销主要学什么
  • 中小企业网站制作费用新东方烹饪学校
  • 毕业设计论文代做网站优化站点
  • 捷信做单网站百度总部地址
  • 公司两个网站如何都备案深圳网络推广怎么做
  • 足球反波胆网站开发互联网关键词优化
  • 网站管理员作用百度关键词指数查询
  • 做网站可以用.cn域名吗网站开发用什么语言
  • 网站开发参数夫唯seo教程
  • 利用淘宝做网站卖货到国外网络营销策略有哪些
  • 网站建设行业细分宁波网络优化seo
  • dede 手机网站模板seo整站优化方案
  • 化妆品行业网站建设方案网络优化培训骗局
  • 黑客技术自学网站产品营销网站建设