|
Country other = (Country) obj;
<span class="hljs-keyword">if (name.equalsIgnoreCase((other.name)))
<span class="hljs-keyword">return <span class="hljs-keyword">true;
<span class="hljs-keyword">return <span class="hljs-keyword">false;
}
}
2. HashMapStructure.java(main class)
<span class="hljs-comment">/**
* @author Arpit Mandliya
*/
<span class="hljs-keyword">public <span class="hljs-keyword">static <span class="hljs-built_in">void main(<span class="hljs-built_in">String[] args) {
Country india=<span class="hljs-keyword">new Country(<span class="hljs-string">"India",<span class="hljs-number">1000);
Country japan=<span class="hljs-keyword">new Country(<span class="hljs-string">"Japan",<span class="hljs-number">10000);
Country france=<span class="hljs-keyword">new Country(<span class="hljs-string">"France",<span class="hljs-number">2000);
Country russia=<span class="hljs-keyword">new Country(<span class="hljs-string">"Russia",<span class="hljs-number">20000);
HashMap<country,<span class="hljs-built_in">string> countryCapitalMap=<span class="hljs-keyword">new HashMap<country,<span class="hljs-built_in">string>();
countryCapitalMap.put(india,<span class="hljs-string">"Delhi");
countryCapitalMap.put(japan,<span class="hljs-string">"Tokyo");
countryCapitalMap.put(france,<span class="hljs-string">"Paris");
countryCapitalMap.put(russia,<span class="hljs-string">"Moscow");
Iterator<country> countryCapitalIter=countryCapitalMap.keySet().iterator();<span class="hljs-comment">//put debug point at this line
<span class="hljs-keyword">while(countryCapitalIter.hasNext())
{
Country countryObj=countryCapitalIter.next();
<span class="hljs-built_in">String capital=countryCapitalMap.get(countryObj);
System.out.println(countryObj.getName()+<span class="hljs-string">"----"+capital);
}
}
}
现在,在第23行设置一个断点,在项目上右击->调试运行(debug as)->java应用(java application)。程序会停在23行,然后在countryCapitalMap上右击,选择“查看”(watch)。将会看到如下的结构:

从上图可以观察到以下几点:
1. 有一个叫做table大小是16的Entry数组。
(编辑:PHP编程网 - 湛江站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|