Java中 map集合能排序吗?
1个回答
展开全部
可以的,Java中的map ,list ,set 三个之间都是可以相互的转换的!
举个例子:map 转换成List 后就可以排序了~
public class test {
public static void main(String[] args) {
Map<String,String> maps = new HashMap<String,String>();
maps.put("1", "one");
maps.put("2", "two");
maps.put("3", "three");
List list = mapTransitionList(maps);
for(int i=0; i<list.size(); i++) {
System.out.println(list.get(i));}}private static List mapTransitionList(Map<String, String> maps) {
List list = new ArrayList();
Iterator iter = maps.entrySet().iterator(); //获得map的Iterator
while(iter.hasNext()) {
举个例子:map 转换成List 后就可以排序了~
public class test {
public static void main(String[] args) {
Map<String,String> maps = new HashMap<String,String>();
maps.put("1", "one");
maps.put("2", "two");
maps.put("3", "three");
List list = mapTransitionList(maps);
for(int i=0; i<list.size(); i++) {
System.out.println(list.get(i));}}private static List mapTransitionList(Map<String, String> maps) {
List list = new ArrayList();
Iterator iter = maps.entrySet().iterator(); //获得map的Iterator
while(iter.hasNext()) {
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询