java关于数据格式的问题

上一个方法传过来的是hashmap的对象temp,存放键值对,里面放的是{a=0,b=e,c=1,d=assa}
.
里面abcd是类型,后面是值。而输出temp.get(i),竟然是 null null null null 4个空,why?我需要的的格式是
a:0
b:e
c:1
d:assa
怎么搞?
我今天脑子糊涂的不行,求助

你需要的是{a:0,b=e,c=1.d=asssa}这样的格式么,如果是,那么你直接可以把map转化为json就好了。
如果你只是单纯的想要这个结构类型,直接

 temp.toString().replace("=",":")

就好了

hashmap取值的方法是temp.get("键值名称")

map 是将key 使用hash 算法转为 下标 去对应的。 你直接用get(i) 当然取出来是null,你要用key值进行取值。

Map map = new HashMap();
map.put("001","xiaoming");
map.put("002","xiaohong");
map.put("003","xiaoliang");
Set set= map.keySet();
for(String key : set){
System.out.println("key":key);
System.out.println("value":map.get(key));
}

通过key来获取value,或者直接toString打印全部

既然key和value都需要,那你吧上一个方法的hashmap 写一个类CommonKeyValue封装key和value,用的时候直接用不是更好.
CommonKeyValue commonKeyValue=new CommonKeyValue();
commonKeyValue.setKey(key);
commonKeyValue.setValue(value);
多个数据就弄成一个List,

楼上ios_king 是正解,遍历hashmap即可

麻烦看一下底层实现,你的get方法要求传的是key,而你传递的是下标,如果真想用下标遍历,建议用Iterator
public V get(Object key) {
if (key == null) {
HashMapEntry e = entryForNullKey;
return e == null ? null : e.value;
}

    // Doug Lea's supplemental secondaryHash function (inlined).
    // Replace with Collections.secondaryHash when the VM is fast enough (http://b/8290590).
    int hash = key.hashCode();
    hash ^= (hash >>> 20) ^ (hash >>> 12);
    hash ^= (hash >>> 7) ^ (hash >>> 4);

    HashMapEntry<K, V>[] tab = table;
    for (HashMapEntry<K, V> e = tab[hash & (tab.length - 1)];
            e != null; e = e.next) {
        K eKey = e.key;
        if (eKey == key || (e.hash == hash && key.equals(eKey))) {
            return e.value;
        }
    }
    return null;
}