早上好。我有类,其中包含以下格式的数据:[int][Object]。我从未使用过类,我通常使用列表、地图,现在我不明白如何在公共类中实现它。如何按类中的字段排序?小心,我的 toString 只显示没有字段编号的字段代码。
I would like to sort this class by size of value[Object]
( "1 1234", "2 35881", ... "7 22" --> "7 22", "1 1234", "2 35881")
public class Record {
private int number;
private Object code;
... Getters/Setters
@Override
public String toString() {
return (String)(this.code);
}
}
public class Storage
{
List<Record> record;
public Storage(){
this.record = new ArrayList<Record>();
}
public void addRecord(Record record) {
this.record.add(record);
}
public Record getRecord(int number){
return this.record.get(number);
}
public void delRecord(int number){
this.record.remove(number);
}
public Integer sizeStorage(){
return record.size();
}
}
public class Start {
public static void main(String[] args) {
System.out.println("Start reading from Xls");
ReaderXls read = new ReaderXls();
Storage storageRZS = readrzs.ReadXls("Text1obj",2,12);
.....
System.out.println(storageRZS.getRecord(5));
System.out.println(storageRZS.getRecord(7));
System.out.println(storageRZS.getRecord(10));
2122
189266
244
The result should be this:
244
2122
189266