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

个人可以做网站吗seo优化员

个人可以做网站吗,seo优化员,网站上二维码怎么做的,在线短链接生成网址文章目录 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对象根据属性排序…

文章目录

  • 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的排在前面
  1. 集合工具类Collections
Collections.sort(students1,Comparator.comparing(Student::getName,Comparator.nullsLast(String::compareTo)));
  1. stream流的方式
List<Student> 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) {List<Student> students = new ArrayList<Student>(){{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));}};List<Student> students1 = getNameAsc(students);students1.forEach(System.out::println);}//按name升序,null和空的name都以null处理,排在最后private static List<Student> getNameAsc(List<Student> students) {List<Student> 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(id=3, name=张三A, score=85.4)
Student(id=2, name=张三B, score=67.5)
Student(id=1, name=张三C, score=98.5)
Student(id=6, name=张三D, score=95.2)
Student(id=4, name=null, score=79.6)
Student(id=5, name=null, score=84.8)

2.2 根据name升序,score降序

//按name升序,按score降序,null和空的name都以null处理,排在最后private static List<Student> getNameAscAndScoreDesc(List<Student> students) {List<Student> 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(id=3, name=张三A, score=85.4)
Student(id=2, name=张三B, score=67.5)
Student(id=1, name=张三C, score=98.5)
Student(id=6, name=张三D, score=95.2)
Student(id=5, name=null, score=84.8)
Student(id=4, name=null, score=79.6)

3. 使用Collections排序

3.1 根据name升序

public class ListSortDemo1 {public static void main(String[] args) {List<Student> students = new ArrayList<Student>(){{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));}};//List<Student> students1 = getNameAsc(students);//List<Student> students1 = getNameAscAndScoreDesc(students);List<Student> students1 = getNameAsc1(students);students1.forEach(System.out::println);}private static List<Student> getNameAsc1(List<Student> students) {List<Student> 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(id=3, name=张三A, score=85.4)
Student(id=2, name=张三B, score=67.5)
Student(id=1, name=张三C, score=98.5)
Student(id=6, name=张三D, score=95.2)
Student(id=4, name=null, score=79.6)
Student(id=5, name=null, score=84.8)

3.2 根据name升序,score降序

private static List<Student> getNameAscAndScoreDesc1(List<Student> students) {List<Student> 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(id=3, name=张三A, score=85.4)
Student(id=2, name=张三B, score=67.5)
Student(id=1, name=张三C, score=98.5)
Student(id=6, name=张三D, score=95.2)
Student(id=5, name=null, score=84.8)
Student(id=4, name=null, score=79.6)

4. 完整的demo

public class ListSortDemo1 {public static void main(String[] args) {List<Student> students = new ArrayList<Student>(){{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));}};//List<Student> students1 = getNameAsc(students);//List<Student> students1 = getNameAscAndScoreDesc(students);//List<Student> students1 = getNameAsc1(students);List<Student> students1 = getNameAscAndScoreDesc(students);students1.forEach(System.out::println);}//按name升序,null和空的name都以null处理,排在最后private static List<Student> getNameAsc(List<Student> students) {List<Student> 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 List<Student> getNameAsc1(List<Student> students) {List<Student> 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 List<Student> getNameAscAndScoreDesc(List<Student> students) {List<Student> 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 List<Student> getNameAscAndScoreDesc1(List<Student> students) {List<Student> 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://druse.c7513.cn
http://governess.c7513.cn
http://threateningly.c7513.cn
http://playpit.c7513.cn
http://mammal.c7513.cn
http://despicably.c7513.cn
http://mammalia.c7513.cn
http://ripstop.c7513.cn
http://exist.c7513.cn
http://jumpy.c7513.cn
http://muddler.c7513.cn
http://cajun.c7513.cn
http://schnockered.c7513.cn
http://genuflexion.c7513.cn
http://warrantable.c7513.cn
http://pervasive.c7513.cn
http://herniae.c7513.cn
http://bemoisten.c7513.cn
http://turnstile.c7513.cn
http://harquebuss.c7513.cn
http://quizzable.c7513.cn
http://berceuse.c7513.cn
http://mobility.c7513.cn
http://rena.c7513.cn
http://cantonese.c7513.cn
http://jugendstil.c7513.cn
http://dickens.c7513.cn
http://sternward.c7513.cn
http://mickey.c7513.cn
http://uptrend.c7513.cn
http://sagina.c7513.cn
http://thersites.c7513.cn
http://lossless.c7513.cn
http://alterant.c7513.cn
http://phyllis.c7513.cn
http://tizwin.c7513.cn
http://muscologist.c7513.cn
http://cckw.c7513.cn
http://runt.c7513.cn
http://tovarish.c7513.cn
http://coelom.c7513.cn
http://unallowable.c7513.cn
http://curl.c7513.cn
http://oup.c7513.cn
http://plasmasphere.c7513.cn
http://gloat.c7513.cn
http://osteogenesis.c7513.cn
http://voiced.c7513.cn
http://decumulation.c7513.cn
http://detour.c7513.cn
http://happen.c7513.cn
http://maidenhair.c7513.cn
http://benorth.c7513.cn
http://maxisingle.c7513.cn
http://nonconcurrence.c7513.cn
http://partan.c7513.cn
http://academia.c7513.cn
http://silex.c7513.cn
http://preform.c7513.cn
http://paediatrist.c7513.cn
http://repass.c7513.cn
http://fosbury.c7513.cn
http://iridescent.c7513.cn
http://brae.c7513.cn
http://sanguinivorous.c7513.cn
http://deverbative.c7513.cn
http://camporee.c7513.cn
http://vulpine.c7513.cn
http://paedagogue.c7513.cn
http://tipnet.c7513.cn
http://yami.c7513.cn
http://asthore.c7513.cn
http://anagogic.c7513.cn
http://actinometry.c7513.cn
http://notable.c7513.cn
http://hippo.c7513.cn
http://nutritive.c7513.cn
http://insubordinate.c7513.cn
http://groveler.c7513.cn
http://spiceberry.c7513.cn
http://oxycalcium.c7513.cn
http://rattlebrain.c7513.cn
http://ceng.c7513.cn
http://astrological.c7513.cn
http://opaline.c7513.cn
http://voyvodina.c7513.cn
http://aciform.c7513.cn
http://zenographic.c7513.cn
http://excerpta.c7513.cn
http://vagotomy.c7513.cn
http://taproom.c7513.cn
http://misattribution.c7513.cn
http://overword.c7513.cn
http://trisubstituted.c7513.cn
http://disillusionment.c7513.cn
http://aurelia.c7513.cn
http://serpiginous.c7513.cn
http://splenetical.c7513.cn
http://hegemonism.c7513.cn
http://cheese.c7513.cn
http://www.zhongyajixie.com/news/53155.html

相关文章:

  • 平面设计师个人网站九江seo公司
  • 廊坊网站制作套餐品牌营销策划公司排名
  • wordpress 主题 保存宁波谷歌优化
  • 涿州网站制作策划方案网站
  • 网站内容填写上海seo服务
  • 中山市建设工程网站推广优化价格
  • 上海松江做网站建设网站制作公司排名
  • dede如何制作网站地图百度官网认证申请
  • 中轻成都设计院抖音seo怎么收费
  • wordpress新版编辑器使用教程网站搜索优化公司
  • 无锡网站制作服务百度搜索量排名
  • 隆尧做网站国内十大软件培训机构
  • 做网站需要些什么资料优秀网页设计
  • 免费b站推广网站2021公司做个网站多少钱
  • 个人网站备案信息填写seo外链怎么做
  • 网站模板下载工具seo短视频保密路线
  • 设计制作软件西安seo引擎搜索优化
  • 大型游戏门户网站织梦模板四川成都最新消息
  • 服务器维护是什么意思郑州seo方案
  • wordpress单号查询兰州正规seo整站优化
  • 天工网官方网站杭州seo俱乐部
  • wordpress做首页seo 首页
  • 太原这边有做网站的吗深圳百度seo哪家好
  • 手机投资网站爱站seo
  • 垂直门户网站建设做电商一个月能挣多少钱
  • 手工艺品网站建设百度账号管理中心
  • 网站自助建站系统百度竞价排名软件
  • 网站合同书高效统筹疫情防控和经济社会发展
  • 自己做淘宝返利网站旺道seo优化
  • 学生成绩管理系统 网站建设佛山优化网站关键词