List转为数组:List<Map<String, Integer>> data = new ArrayList<Map<String, Integer>>();
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
2个回答
2015-04-11
展开全部
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class $ {
public static void main(String[] args) {
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
list.add(getData(0));
list.add(getData(3));
list.add(getData(05));
list.add(getData(6));
list.add(getData(2));
System.out.println("排序前" + list);
Collections.sort(list, new Comparator<Map<String, String>>() {
public int compare(Map<String, String> o1, Map<String, String> o2) {
return o1.get("countScore").compareTo(o2.get("countScore"));
}
});
System.out.println("排序后" + list);
}
private static Map<String, String> getData(int num) {
Map<String, String> map = new HashMap<String, String>();
map.put("countScore", String.valueOf(num));
return map;
}
}
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class $ {
public static void main(String[] args) {
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
list.add(getData(0));
list.add(getData(3));
list.add(getData(05));
list.add(getData(6));
list.add(getData(2));
System.out.println("排序前" + list);
Collections.sort(list, new Comparator<Map<String, String>>() {
public int compare(Map<String, String> o1, Map<String, String> o2) {
return o1.get("countScore").compareTo(o2.get("countScore"));
}
});
System.out.println("排序后" + list);
}
private static Map<String, String> getData(int num) {
Map<String, String> map = new HashMap<String, String>();
map.put("countScore", String.valueOf(num));
return map;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询