Collections sort not being accepted by Eclipse

后端 未结 5 1593
梦如初夏
梦如初夏 2021-01-19 06:58
    import java.io.BufferedReader;
    import java.util.Collections;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader         


        
5条回答
  •  星月不相逢
    2021-01-19 07:16

    For the first issue, the problem is fairly simple. oneName is a String, and myCelebrityList is a collection of CelebrityNamesFile- which means that you can only add objects to the collection of type CelebrityNamesFile.

    For the second issue, your problem is that the CelebrityNamesFile class does not implement the Comparable interface. Sorting requires that an ordering is implemented for the list element type, e.g. by implementing Comparable for the class or providing a Comparator to the sort.

提交回复
热议问题