简介 目录 评价 推荐
  • deliveryBoy 2020-12-24

    自定类型不能直接排序,因为没有实现Comparable接口

    0赞 · 0采集
  • 哦哦哦long 2020-01-31

    sort()

    截图
    0赞 · 0采集
  • orangewangjie3473319 2020-01-16

    sort方法  和 Comparable接口

    截图
    0赞 · 0采集
  • orangewangjie3473319 2020-01-16

    排序 sort

    截图
    0赞 · 0采集
  • 好雨rain 2019-11-01

    sort排序的元素要实现Comparable接口

    80%

    截图
    0赞 · 0采集
  • 慕少1344137 2019-09-22

    studentList.add(new Student(1 + "","小明"));
    为什么是这样书写  (1+"")这就是一个字符串啊,数字+""就转成字符串了,等同于"1"。

    0赞 · 0采集
  • qq_慕勒0516037 2019-09-20

    student不是comparable接口的实现类

    所以不能sort(student)

    0赞 · 0采集
  • 許尔摩斯_ 2019-07-22

    利用Collections.sort()方法对各种类进行排序https://img.mukewang.com/5d3565340001ed6e05440525.jpg

    0赞 · 0采集
  • 你的学长 2019-06-01

    对于像Integer这样基本类型的包装类以及String泛型的ListCollections.sort()都是非常管用非常方便的

    https://img4.mukewang.com/5cf270930001dab504590545.jpg

    对于其他泛型元素必须实现Comparable接口

    0赞 · 0采集
  • 慕勒8415117 2018-11-06

    package com.imooc_b;


    import java.util.ArrayList;

    import java.util.Collections;

    import java.util.List;

    import java.util.Random;


    public class CollectionsTset {

    public void Sort() {

    List<String> listTset = new ArrayList<String>();

    Random random = new Random();

    // 生成十条不重复的字符串(由数字和字母组成)

    for (int i = 0; i < 10; i++) {

    StringBuffer buffer = new StringBuffer();

    do {

    // 字符串长度为10以内的整数,nextInt()范围为(0,9),字符串长度不想设置为空就加1

    int k = random.nextInt(9) + 1;

    // 随机生成字符串

    for (int j = 0; j < k; j++) {

    int b;

    do {

    // 随机生成0到122的数字,0到9表示数字字符,65到90表示'A'到'Z'

    // 97到122表示'a'到'z'

    b = (int) (Math.random() * 123);

    }

    // 当生成的字符为'0'到'9'或'a'到'z'或'A'到'Z'时跳出

    while (!((b >= 0 && b <= 9) || (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z')));

    if (b >= 0 && b <= 9) {

    String in = Integer.toString(b);

    buffer.append(in);

    } else {

    char ch = (char) b;

    String in = String.valueOf(ch);

    buffer.append(in);

    }

    }

    } while (listTset.contains(buffer.toString()));

    // 如果list没有该字符串就加入

    listTset.add(buffer.toString());

    }


    System.out.println("-------排序前----------");

    for (String string : listTset) {

    System.out.println("元素:" + string);

    }

    Collections.sort(listTset);

    System.out.println("---------排序后---------");

    for (String string : listTset) {

    System.out.println("元素:" + string);

    }


    }


    public static void main(String[] args) {

    CollectionsTset ct = new CollectionsTset();

    ct.Sort();


    }


    }


    1赞 · 0采集
  • 少年_他 2018-10-15

    studentList.add(new Student(1 + "","小明"));
    为什么是这样书写  (1+"")这就是一个字符串啊,数字+""就转成字符串了,等同于"1"。

    Collections.sort(studentList);
    会报错//Collections.sort()方法,必须有comparable接口

    0赞 · 0采集
  • 慕桂英6340135 2018-08-31

    https://img1.mukewang.com/5b88ff570001536502730040.jpg 自定义的不能比较


    0赞 · 0采集
  • qq_飞翔的勇气_0 2018-07-30

    collection.sort()方法对元素进行排序,列表中的元素都必需实现 Comparable 接口,否则不能使用 sort()方法排序

    0赞 · 0采集
  • 妮妮慕莱坞3017812 2018-07-29
    public void testSort3(){
    List<Student> studentList=new ArrayList<Student>();
    studentList.add(new Student(1+"","小明"));
    studentList.add(new Student(2+"","小红"));
    studentList.add(new Student(3+"","小兰"));
    System.out.println("----排序前-------");
    for(Student student:studentList){
    SYstem.out.println("学生:"+student.name);}
    Collections.sort(studentList);}


    0赞 · 0采集
  • BirdOfV 2018-05-19

    Collections工具类---sort()

    注意点:不能使用自定义的,若要使用则要实现Comparable接口。

    截图
    1赞 · 0采集
  • VVe 2018-02-27
    Collections的sort()方法只对String,Integer类管用,因为他们是Comparable接口的实现类,其他类型不是。
    截图
    0赞 · 1采集
  • 种花的小裁缝 2017-11-01
    sort (comparable接口)
    截图
    0赞 · 0采集
  • Jinezxcv 2017-09-05
    collection.sort()方法对元素进行排序,列表中的元素都必需实现 Comparable 接口,否则不能使用 sort()方法排序
    0赞 · 1采集
  • 追梦82 2017-08-12
    Collections.sort()方法不适用与List<Student>. 原因:Student不是有界参数<T 到Comparable<? super T>>的有效替代项。 sort方法实现了Comparable接口。
    0赞 · 2采集
  • 慕粉5101576 2017-07-13
    Collections.sort()方法不适用与List<Student>. 原因:Student不是有界参数<T 到Comparable<? super T>>的有效替代项。 sort方法实现了Comparable接口。
    截图
    0赞 · 0采集
  • 触摸未来 2017-07-11
    集合的sort方法的参数必须是实现Comparable接口的对象的列表
    0赞 · 0采集
  • 小光头 2017-07-09
    collection.sort() 排序方法对于泛型 List<Integer>/List<String>/List<包装类
    截图
    0赞 · 0采集
  • 慕粉3974963 2017-07-07
    Collection工具类(java.util.Collection):是java集合框架中,用来操作集合对象的工具类,也是java集合框架的成员。 .sort() (静态方法)对List接口的对象的元素进行排序。 要求:列表中的所有元素都必须实现Comparable接口。
    截图
    0赞 · 0采集
  • 六然 2017-06-23
    Collections.sort()方法不适用与List<Student>. 原因:Student不是有界参数<T 到Comparable<? super T>>的有效替代项。 sort方法实现了Comparable接口。
    截图
    0赞 · 2采集
  • Meet相识 2017-05-30
    HashSet中的Contains()方法先比较HashCode,在比较equals,ArrayList中的Contains()只比较equals,若有特殊需求,需重写类的hashcode和equals方法,关于hashcode方法。设计到hash算法,待解决
    0赞 · 0采集
  • 宇智波丶卡卡西 2017-04-29
    若要使用Collections.sort() 则可在List<Integer String >等 若要用自己的类 List<Student> 则必须实现comparable方法
    截图
    0赞 · 0采集
  • 爱笑的毛毛虫 2017-04-25
    排序类型
    截图
    0赞 · 0采集
  • 慕函数1733451 2017-04-20
    前引方便
    截图
    0赞 · 0采集
  • 小qishi 2017-04-14
    Collections的sort 方法介绍:
    截图
    0赞 · 0采集
  • weibo_sz小泽_0 2017-04-05
    sort对象必须实现Comparable接口。
    0赞 · 0采集
数据加载中...
开始学习 免费