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

网站优化排名易下拉排名农业网站平台建设方案

网站优化排名易下拉排名,农业网站平台建设方案,上海网站建设caiyiduo,百度最贵关键词排名文章目录 JDK8对List对象根据属性排序1. 被排序字段为null或者空时候报错2. 使用Stream流排序2.1 根据name升序2.2 根据name升序#xff0c;score降序 3. 使用Collections排序3.1 根据name升序3.2 根据name升序#xff0c;score降序 4. 完整的demo JDK8对List对象根据属性排序… 文章目录 JDK8对List对象根据属性排序1. 被排序字段为null或者空时候报错2. 使用Stream流排序2.1 根据name升序2.2 根据name升序score降序 3. 使用Collections排序3.1 根据name升序3.2 根据name升序score降序 4. 完整的demo JDK8对List对象根据属性排序 1. 被排序字段为null或者空时候报错 被排序字段为null或者空的时候报java.lang.NullPointerException Exception in thread main java.lang.NullPointerExceptionat java.util.Comparator.lambda$comparing$77a9974f$1(Comparator.java:469)at java.util.TimSort.countRunAndMakeAscending(TimSort.java:356)at java.util.TimSort.sort(TimSort.java:220)at java.util.Arrays.sort(Arrays.java:1512)at java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:348)at java.util.stream.Sink$ChainedReference.end(Sink.java:258)at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)at com.stormkai.jh.ListSortDemo1.getNameAsc(ListSortDemo1.java:40)at com.stormkai.jh.ListSortDemo1.main(ListSortDemo1.java:19)使用以下方式处理 Comparator.nullsLast排序字段为null的排在后面Comparator.nullsFirst排序字段为null的排在前面 集合工具类Collections Collections.sort(students1,Comparator.comparing(Student::getName,Comparator.nullsLast(String::compareTo)));stream流的方式 ListStudent students1 students.stream().map(student - {if(.equals(student.getName())){student.setName(null);}return student;}).sorted(Comparator.comparing(Student::getName,Comparator.nullsLast(String::compareTo))).collect(Collectors.toList())2. 使用Stream流排序 Student.java Data AllArgsConstructor public class Student {private Integer id;private String name;private double score; }2.1 根据name升序 public class ListSortDemo1 {public static void main(String[] args) {ListStudent students new ArrayListStudent(){{add(new Student(1,张三C,98.50d));add(new Student(2,张三B,67.50d));add(new Student(3,张三A,85.40d));add(new Student(4,,79.60d));add(new Student(5,null,84.80d));add(new Student(6,张三D,95.20d));}};ListStudent students1 getNameAsc(students);students1.forEach(System.out::println);}//按name升序null和空的name都以null处理排在最后private static ListStudent getNameAsc(ListStudent students) {ListStudent students1 students.stream().map(student - {if(.equals(student.getName())){student.setName(null);}return student;}).sorted(Comparator.comparing(Student::getName,Comparator.nullsLast(String::compareTo))).collect(Collectors.toList());return students1;} }执行结果 Student(id3, name张三A, score85.4) Student(id2, name张三B, score67.5) Student(id1, name张三C, score98.5) Student(id6, name张三D, score95.2) Student(id4, namenull, score79.6) Student(id5, namenull, score84.8)2.2 根据name升序score降序 //按name升序按score降序null和空的name都以null处理排在最后private static ListStudent getNameAscAndScoreDesc(ListStudent students) {ListStudent students1 students.stream().map(student - {if(.equals(student.getName())){student.setName(null);}return student;}).sorted(Comparator.comparing(Student::getName,Comparator.nullsLast(String::compareTo)).reversed().thenComparing(Student::getScore).reversed()).collect(Collectors.toList());return students1;}输出结果 Student(id3, name张三A, score85.4) Student(id2, name张三B, score67.5) Student(id1, name张三C, score98.5) Student(id6, name张三D, score95.2) Student(id5, namenull, score84.8) Student(id4, namenull, score79.6)3. 使用Collections排序 3.1 根据name升序 public class ListSortDemo1 {public static void main(String[] args) {ListStudent students new ArrayListStudent(){{add(new Student(1,张三C,98.50d));add(new Student(2,张三B,67.50d));add(new Student(3,张三A,85.40d));add(new Student(4,,79.60d));add(new Student(5,null,84.80d));add(new Student(6,张三D,95.20d));}};//ListStudent students1 getNameAsc(students);//ListStudent students1 getNameAscAndScoreDesc(students);ListStudent students1 getNameAsc1(students);students1.forEach(System.out::println);}private static ListStudent getNameAsc1(ListStudent students) {ListStudent students1 students.stream().map(student - {if (.equals(student.getName())) {student.setName(null);}return student;}).collect(Collectors.toList());Collections.sort(students1,Comparator.comparing(Student::getName,Comparator.nullsLast(String::compareTo)));return students1;} }输出结果 Student(id3, name张三A, score85.4) Student(id2, name张三B, score67.5) Student(id1, name张三C, score98.5) Student(id6, name张三D, score95.2) Student(id4, namenull, score79.6) Student(id5, namenull, score84.8)3.2 根据name升序score降序 private static ListStudent getNameAscAndScoreDesc1(ListStudent students) {ListStudent students1 students.stream().map(student - {if (.equals(student.getName())) {student.setName(null);}return student;}).collect(Collectors.toList());Collections.sort(students1,Comparator.comparing(Student::getName,Comparator.nullsLast(String::compareTo)).reversed().thenComparing(Student::getScore).reversed());return students1;}输出结果 Student(id3, name张三A, score85.4) Student(id2, name张三B, score67.5) Student(id1, name张三C, score98.5) Student(id6, name张三D, score95.2) Student(id5, namenull, score84.8) Student(id4, namenull, score79.6)4. 完整的demo public class ListSortDemo1 {public static void main(String[] args) {ListStudent students new ArrayListStudent(){{add(new Student(1,张三C,98.50d));add(new Student(2,张三B,67.50d));add(new Student(3,张三A,85.40d));add(new Student(4,,79.60d));add(new Student(5,null,84.80d));add(new Student(6,张三D,95.20d));}};//ListStudent students1 getNameAsc(students);//ListStudent students1 getNameAscAndScoreDesc(students);//ListStudent students1 getNameAsc1(students);ListStudent students1 getNameAscAndScoreDesc(students);students1.forEach(System.out::println);}//按name升序null和空的name都以null处理排在最后private static ListStudent getNameAsc(ListStudent students) {ListStudent students1 students.stream().map(student - {if(.equals(student.getName())){student.setName(null);}return student;}).sorted(Comparator.comparing(Student::getName,Comparator.nullsLast(String::compareTo))).collect(Collectors.toList());return students1;}private static ListStudent getNameAsc1(ListStudent students) {ListStudent students1 students.stream().map(student - {if (.equals(student.getName())) {student.setName(null);}return student;}).collect(Collectors.toList());Collections.sort(students1,Comparator.comparing(Student::getName,Comparator.nullsLast(String::compareTo)));return students1;}//按name升序按score降序null和空的name都以null处理排在最后private static ListStudent getNameAscAndScoreDesc(ListStudent students) {ListStudent students1 students.stream().map(student - {if(.equals(student.getName())){student.setName(null);}return student;}).sorted(Comparator.comparing(Student::getName,Comparator.nullsLast(String::compareTo)).reversed().thenComparing(Student::getScore).reversed()).collect(Collectors.toList());return students1;}private static ListStudent getNameAscAndScoreDesc1(ListStudent students) {ListStudent students1 students.stream().map(student - {if (.equals(student.getName())) {student.setName(null);}return student;}).collect(Collectors.toList());Collections.sort(students1,Comparator.comparing(Student::getName,Comparator.nullsLast(String::compareTo)).reversed().thenComparing(Student::getScore).reversed());return students1;} }
文章转载自:
http://www.morning.qnlbb.cn.gov.cn.qnlbb.cn
http://www.morning.mkfr.cn.gov.cn.mkfr.cn
http://www.morning.hytfz.cn.gov.cn.hytfz.cn
http://www.morning.rnxs.cn.gov.cn.rnxs.cn
http://www.morning.wffxr.cn.gov.cn.wffxr.cn
http://www.morning.lwnb.cn.gov.cn.lwnb.cn
http://www.morning.htbbp.cn.gov.cn.htbbp.cn
http://www.morning.zqfz.cn.gov.cn.zqfz.cn
http://www.morning.wxfgg.cn.gov.cn.wxfgg.cn
http://www.morning.ns3nt8.cn.gov.cn.ns3nt8.cn
http://www.morning.ldwxj.cn.gov.cn.ldwxj.cn
http://www.morning.kxyqy.cn.gov.cn.kxyqy.cn
http://www.morning.jnkng.cn.gov.cn.jnkng.cn
http://www.morning.xwlhc.cn.gov.cn.xwlhc.cn
http://www.morning.fkdts.cn.gov.cn.fkdts.cn
http://www.morning.lgrkr.cn.gov.cn.lgrkr.cn
http://www.morning.wpcfm.cn.gov.cn.wpcfm.cn
http://www.morning.jlxqx.cn.gov.cn.jlxqx.cn
http://www.morning.dyxzn.cn.gov.cn.dyxzn.cn
http://www.morning.xpfwr.cn.gov.cn.xpfwr.cn
http://www.morning.wfmqc.cn.gov.cn.wfmqc.cn
http://www.morning.khzml.cn.gov.cn.khzml.cn
http://www.morning.mdpkf.cn.gov.cn.mdpkf.cn
http://www.morning.lsfbb.cn.gov.cn.lsfbb.cn
http://www.morning.nrzkg.cn.gov.cn.nrzkg.cn
http://www.morning.rqfzp.cn.gov.cn.rqfzp.cn
http://www.morning.gcdzp.cn.gov.cn.gcdzp.cn
http://www.morning.qhnmj.cn.gov.cn.qhnmj.cn
http://www.morning.fkwgk.cn.gov.cn.fkwgk.cn
http://www.morning.ssqrd.cn.gov.cn.ssqrd.cn
http://www.morning.ktbjk.cn.gov.cn.ktbjk.cn
http://www.morning.hfnbr.cn.gov.cn.hfnbr.cn
http://www.morning.bnjnp.cn.gov.cn.bnjnp.cn
http://www.morning.rmkyb.cn.gov.cn.rmkyb.cn
http://www.morning.xxhc.cn.gov.cn.xxhc.cn
http://www.morning.rbrhj.cn.gov.cn.rbrhj.cn
http://www.morning.zlkps.cn.gov.cn.zlkps.cn
http://www.morning.msbct.cn.gov.cn.msbct.cn
http://www.morning.ydhck.cn.gov.cn.ydhck.cn
http://www.morning.rjhts.cn.gov.cn.rjhts.cn
http://www.morning.mpszk.cn.gov.cn.mpszk.cn
http://www.morning.tgmfg.cn.gov.cn.tgmfg.cn
http://www.morning.kksjr.cn.gov.cn.kksjr.cn
http://www.morning.hqqpy.cn.gov.cn.hqqpy.cn
http://www.morning.wbyqy.cn.gov.cn.wbyqy.cn
http://www.morning.fhrt.cn.gov.cn.fhrt.cn
http://www.morning.ftlgy.cn.gov.cn.ftlgy.cn
http://www.morning.smdiaosu.com.gov.cn.smdiaosu.com
http://www.morning.nbfkk.cn.gov.cn.nbfkk.cn
http://www.morning.xprzq.cn.gov.cn.xprzq.cn
http://www.morning.cpwmj.cn.gov.cn.cpwmj.cn
http://www.morning.mnkz.cn.gov.cn.mnkz.cn
http://www.morning.27asw.cn.gov.cn.27asw.cn
http://www.morning.ypklb.cn.gov.cn.ypklb.cn
http://www.morning.pftjj.cn.gov.cn.pftjj.cn
http://www.morning.krjyq.cn.gov.cn.krjyq.cn
http://www.morning.mhpkz.cn.gov.cn.mhpkz.cn
http://www.morning.mzcrs.cn.gov.cn.mzcrs.cn
http://www.morning.gnghp.cn.gov.cn.gnghp.cn
http://www.morning.yrctp.cn.gov.cn.yrctp.cn
http://www.morning.rwlsr.cn.gov.cn.rwlsr.cn
http://www.morning.rmpfh.cn.gov.cn.rmpfh.cn
http://www.morning.rsbqq.cn.gov.cn.rsbqq.cn
http://www.morning.flmxl.cn.gov.cn.flmxl.cn
http://www.morning.myfwb.cn.gov.cn.myfwb.cn
http://www.morning.cfcpb.cn.gov.cn.cfcpb.cn
http://www.morning.ylrxd.cn.gov.cn.ylrxd.cn
http://www.morning.bpkqd.cn.gov.cn.bpkqd.cn
http://www.morning.cyjjp.cn.gov.cn.cyjjp.cn
http://www.morning.jxpwr.cn.gov.cn.jxpwr.cn
http://www.morning.kvzvoew.cn.gov.cn.kvzvoew.cn
http://www.morning.gcqs.cn.gov.cn.gcqs.cn
http://www.morning.mmtbn.cn.gov.cn.mmtbn.cn
http://www.morning.ckcjq.cn.gov.cn.ckcjq.cn
http://www.morning.alive-8.com.gov.cn.alive-8.com
http://www.morning.nkpls.cn.gov.cn.nkpls.cn
http://www.morning.wnhgb.cn.gov.cn.wnhgb.cn
http://www.morning.bsqbg.cn.gov.cn.bsqbg.cn
http://www.morning.wptrm.cn.gov.cn.wptrm.cn
http://www.morning.rsdm.cn.gov.cn.rsdm.cn
http://www.tj-hxxt.cn/news/240727.html

相关文章:

  • 哈尔滨住房和城乡建设局网站首页抖音开放平台是什么
  • 什么是网站模板设计Wordpress 淘宝客 页面
  • 中国建设教育协会网站腾讯企业邮箱pc版入口
  • 鹰潭做网站公司还能电子商务网站建设
  • 西部数码网站流量怎么充互联网公司有国企吗
  • 电子商务网站建设的期中考试地方门户网站运营
  • 营销型网站制作的目的是设计师网上接单软件
  • 网站图标下载河池个人网站开发公司
  • 网站推广app下载上海最近新闻
  • 论述网站建设的主要步骤企业产品推广平台
  • 广州云购网站建设wordpress主题文章页
  • 网站制作工作室制作平台辛集做网站
  • 互联网站建设机构网站页面模板
  • 中国银行全球门户网站京东企业门户
  • 建设电商网站的技术可行性南宁定制网站制作网络公司
  • 源码 网站建设教程中国做网站的网站
  • 山西做网站如何选择专业网站制作公司咨询
  • 做网站公司什么条件网站开发的选择是什么
  • 厦门小型网站建设电商商城开发
  • 吉安网站建设优化服务哪些网站推广公司
  • 普法网站建设长沙网站建设公司招聘
  • 山东网站建设是什么优秀手机网站模板图片
  • 网站后台字体安装网站建设贵阳
  • 高校网站建设的重要性软件定制合同模板
  • 抚州网站建设公司广东深圳市宝安区
  • 遵义做网站哪个公司最好沈阳企业网站开发
  • 购买网站模板怎么用外贸网店平台
  • 如何进入网站后台地址wordpress 多说 社交登陆
  • 品牌形象网站源码seo教程技术资源
  • 珠海市官网网站建设品牌响应式网站手机