import java.util.IdentityHashMap ;
import java.util.HashMap ;
import java.util.Set ;
import java.util.Iterator ;
import java.util.Map ;
class Person{
private String name ;
private int age ;
public Person(String name,int age){
this.name = name ;
this.age = age ;
}
public boolean equals(Object obj){
if(this==obj){
return true ;
}
if(!(obj instanceof Person)){
return false ;
}
Person p = (Person)obj ;
if(this.name.equals(p.name)&&this.age==p.age){
return true ;
}else{
return false ;
}
}
public int hashCode(){
return this.name.hashCode() * this.age ;
}
public String toString(){
return "姓名:" + this.name + ",年龄:" + this.age ;
}
};
public class IdentityHashMapDemo01{
public static void main(String args[]){
Map<Person,String> map = null ; // 声明Map对象
map = new HashMap<Person,String>() ;
map.put(new Person("张三",30),"zhangsan_1") ; // 加入内容
map.put(new Person("张三",30),"zhangsan_2") ; // 加入内容
map.put(new Person("李四",31),"lisi") ; // 加入内容
Set<Map.Entry<Person,String>> allSet = null ; // 准备使用Set接收全部内容
allSet = map.entrySet() ;
Iterator<Map.Entry<Person,String>> iter = null ;
iter = allSet.iterator() ;
while(iter.hasNext()){
Map.Entry<Person,String> me = iter.next() ;
System.out.println(me.getKey() + " --> " + me.getValue()) ;
}
}
};
import java.util.IdentityHashMap ;
import java.util.Set ;
import java.util.Iterator ;
import java.util.Map ;
class Person{
private String name ;
private int age ;
public Person(String name,int age){
this.name = name ;
this.age = age ;
}
public boolean equals(Object obj){
if(this==obj){
return true ;
}
if(!(obj instanceof Person)){
return false ;
}
Person p = (Person)obj ;
if(this.name.equals(p.name)&&this.age==p.age){
return true ;
}else{
return false ;
}
}
public int hashCode(){
return this.name.hashCode() * this.age ;
}
public String toString(){
return "姓名:" + this.name + ",年龄:" + this.age ;
}
};
public class IdentityHashMapDemo02{
public static void main(String args[]){
Map<Person,String> map = null ; // 声明Map对象
map = new IdentityHashMap<Person,String>() ;
map.put(new Person("张三",30),"zhangsan_1") ; // 加入内容
map.put(new Person("张三",30),"zhangsan_2") ; // 加入内容
map.put(new Person("李四",31),"lisi") ; // 加入内容
Set<Map.Entry<Person,String>> allSet = null ; // 准备使用Set接收全部内容
allSet = map.entrySet() ;
Iterator<Map.Entry<Person,String>> iter = null ;
iter = allSet.iterator() ;
while(iter.hasNext()){
Map.Entry<Person,String> me = iter.next() ;
System.out.println(me.getKey() + " --> " + me.getValue()) ;
}
}
};

最新文章

  1. 使用python处理子域名爆破工具subdomainsbrute结果txt
  2. 畅通工程——D
  3. 将页面打印成excel
  4. python算法——第四天
  5. JAVA中的NIO(二)
  6. CSS3--动态实现ToolTip效果(实例)
  7. SQL 面试题(一)
  8. php中文编码
  9. DeflateStream类
  10. Lucene全文检索学习笔记
  11. EC+VO+SCOPE for ES3
  12. linux(ubuntu)环境下安装IDEA
  13. 进程间通信——IPC之共享内存
  14. Codeforces 1110D. Jongmah 动态规划
  15. 转://Oracle数据库补丁分析实践
  16. (转)c++ 回调函数
  17. Houdini技术体系 过程化地形系统(一):Far Cry5的植被系统分析
  18. TextView字体,行距,html格式,超链接,对大长度的设定
  19. [LeetCode] 72. Edit Distance_hard tag: Dynamic Programming
  20. [LintCode] 394. Coins in a Line_ Medium tag:Dynamic Programming_博弈

热门文章

  1. js--滑动块
  2. Primecoin服务端更新--操作流程
  3. Firefox 的 hack 及 问题
  4. Django 学习之中间件Middleware
  5. 设计模式课程 设计模式精讲 11-2 装饰者模式coding
  6. java实现经典排序算法
  7. 让tableView的高度等于contentSize的高度、动态调整tableView的高度、tableView的高度自适应布局
  8. Linux学习计划中遇到的问题记录
  9. 常用的HBase命令
  10. jqueery easyui tree把已选中的节点数据拼成json或者数组(非常重要)