Map中的value类型为数组时,怎么输出这个数组?
我把Map中value分别定义为int[](基本类型数组)和String[](引用型数组),代码和结果如下:/* int[] */
import java.util.Map;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
public class MapTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Map <String, int[]> m1=new HashMap<String,int[]>();
String key1="Lucy";
String key2="Lily";
int[] m2={100,10,1};
int[] m3={1,10,100};
m1.put(key1, m2);
m1.put(key2, m3);
System.out.println(m1.get(key1));
System.out.println(m1.containsKey("Lily"));
System.out.println(m1.size());
}
}
输出结果为: [I@139a55
true
2
/* String[] */
import java.util.Map;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
public class MapTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Map <String, String[]> m1=new HashMap<String,String[]>();
String key1="Lucy";
String key2="Lily";
String[] m2={"Lucy的成绩","100","A"};
String[] m3={"Lily的成绩","88","B"};
m1.put(key1, m2);
m1.put(key2, m3);
System.out.println(m1.get(key1));
System.out.println(m1.containsKey("Lily"));
System.out.println(m1.size());
}
}
输出结果为: [Ljava.lang.String;@139a55
true
2
输出Map类型中的value时,结果都是一串地址,怎么得到值?