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);
      }

     }

    }

  • 相关阅读:
    GO 函数的参数
    GO 函数
    GO 指针
    GO 结构体
    GO 接口
    码云git常用命令
    GO Map的初步使用
    GO Slice
    GO 数组
    GO 键盘输入和打印输出
  • 原文地址:https://www.cnblogs.com/mabel/p/5816038.html
Copyright © 2011-2022 走看看