containsKey返回true而期望为false

时间:2016-09-15 17:30:39

标签: hashmap containskey

adb

在上面的代码中,我得到import java.util.HashMap; public class Chapter1_Problem_1_1 { public static void main(String[] args) { String str = "bacdee"; int j = 0; for(int i=0; i< str.length(); i++) { char ch = str.charAt(i); String s = new String(new char[] {ch}); HashMap<String, Integer> map = new HashMap<String, Integer>(); if (map.containsKey(s)) { System.out.println("false"); } else { map.put(s, j++); System.out.println("true:: " + s); } } } } 为真的最后一个字母“e”不知道为什么,它应该是假的;任何想法为什么会这样?

0 个答案:

没有答案
相关问题