zoukankan      html  css  js  c++  java
  • listDemo

    package test1;

    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.List;

    public class ListExample {

     public static void main(String[] args) {

      new ListExample().testList();

     }

     private void testList() {

      List<Mother> list = new ArrayList<>();

      list.add(new Mother("1"));
      list.add(new Mother("3"));
      list.add(new Mother("2"));


      sortList(list);

      printLIst(list);
     }

     private void printLIst(List<Mother> list) {
      for (Mother obj : list) {
       System.out.println(obj);
       // obj.speak();
      }
     }

     private void sortList(List<Mother> list) {
      Collections.sort(list);
     }

     public class Mother implements Comparable<Mother> {

      public Mother(String name2) {
       this.name = name2;
      }

      public String name;
      String foot;
      String mouth = " ";

      void speak() {
       System.out.println(name + " is speaking.... hahahahaha....");
      }

      @Override
      public String toString() {
       return name + mouth;

      }

      @Override
      public int compareTo(Mother o) {
       return -this.name.compareTo(o.name);
      }

     }

    }

  • 相关阅读:
    TypeScript--变量
    TypeScript--Hello
    前端跨域的方式
    内存泄漏与垃圾回收机制
    前端拷贝
    React生命周期16版本
    Redux三大原则
    IE6常见CSS解析Bug及hack
    Redux的应用
    vue-router-基础
  • 原文地址:https://www.cnblogs.com/mabel/p/5816038.html
Copyright © 2011-2022 走看看