LinkedHashMap到底是有序还是无序
展开全部
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class Demo{
public static void main(String[] args) {
Map m = new HashMap();
m.put("001","张三");
m.put("005","李四");
m.put("003","王一");
Set s = m.keySet();
Iterator it = s.iterator();
System.out.println("map里面的元素为:");
while(it.hasNext()){
String a = (String)(it.next());
String b = (String)(m.get(a));
System.out.println(a+" "+b);
}
}
}
我改了你的代码,但是我的结果是李四张三王一
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class Demo{
public static void main(String[] args) {
Map m = new HashMap();
m.put("001","张三");
m.put("005","李四");
m.put("003","王一");
Set s = m.keySet();
Iterator it = s.iterator();
System.out.println("map里面的元素为:");
while(it.hasNext()){
String a = (String)(it.next());
String b = (String)(m.get(a));
System.out.println(a+" "+b);
}
}
}
我改了你的代码,但是我的结果是李四张三王一
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询