java List 排序,升序,降序
原创
©著作权归作者所有:来自51CTO博客作者wx5b6d6c951e615的原创作品,请联系作者获取转载授权,否则将追究法律责任
import java.util.*;
public class EntrySets {
public static void main(String[] args) {
Map<Object, Object> map = new HashMap<Object, Object>();
map.put("k1", "v1");
map.put("k2", "v2");
getItem(map);
List<Object> kk = new ArrayList<Object>();
kk.add("1");
kk.add("aa");
kk.add("A");
print(sortList(kk));
}
static void getItem(Map map) {
map.forEach((key, value) -> print(key + ":" + value));
}
static void iterByKey(Map map) {
/** iter map by key */
for (Object k : map.keySet()) {
String v = map.get(k).toString();
}
}
static void print(Object o) {
System.out.println(o);
}
static List sortList(List list){
Collections.sort(list);
// 反转
//Collections.reverse(list);
return list ;
}
}