Is the key in a Java Map case-sensitive or not?

更新于
2026-08-26 07:25:51
27阅读来源:SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计106个文字,预计阅读时间需要1分钟。

Is the key in a Java Map case-sensitive or not?

javapublic static void main(String[] args) { Map map=new HashMap(); map.put(strain, s1); map.put(sTrain, s2); System.out.println(map); map.put(strain, s3); System.out.println(map);}

public static void main(String[] args) {
Map<String, String> map = new HashMap<>();

map.put("strain", "s1");
map.put("sTrain", "s2");

System.out.println(map);

map.put("strain", "s3");
System.out.println(map);
}

output

{strain=s1, sTrain=s2}
{strain=s3, sTrain=s2}

由此可见,Map的key是对大小写敏感的。

阅读全文

本文共计106个文字,预计阅读时间需要1分钟。

Is the key in a Java Map case-sensitive or not?

javapublic static void main(String[] args) { Map map=new HashMap(); map.put(strain, s1); map.put(sTrain, s2); System.out.println(map); map.put(strain, s3); System.out.println(map);}

public static void main(String[] args) {
Map<String, String> map = new HashMap<>();

map.put("strain", "s1");
map.put("sTrain", "s2");

System.out.println(map);

map.put("strain", "s3");
System.out.println(map);
}

output

{strain=s1, sTrain=s2}
{strain=s3, sTrain=s2}

由此可见,Map的key是对大小写敏感的。

阅读全文