通过Object.attribute [Java]对Map <string,myobj>进行排序

时间:2018-05-01 17:48:00

标签: java android

我有一个包含字符串和对象的Map,我想根据对象属性进行排序。

public class Foo{
     public long timestamp,
     public String name;
     public Foo(long timestamp,String name){
          this.timestamp = timestamp;
          this.name = name;
    }
}
public static main(){
    Map<String,Foo> map = new HashMap<String,Foo>(0);
    for(int i; i<1000;i++){
          //getting the key and filling the Foo objects
          Foo foo = new Foo(datetime,name);
          String key = i;
          map.put(key,Foo);
    }
  //sorting
   Map<String,Foo> sortedMap = sortData(map);

}
public Map<String,Foo> sortData(Map<String map,Foo> map){
           //SORTING HERE THE MAP BASED ON THE TIMESTAMP
}

排序基于Foo对象的timestamp属性。我该怎么办?

0 个答案:

没有答案