吴裕雄--天生自然java开发常用类库学习笔记:IdentityHashMap类
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()) ;
}
}
};
吴裕雄--天生自然java开发常用类库学习笔记:IdentityHashMap类的更多相关文章
- 吴裕雄--天生自然java开发常用类库学习笔记:定时调度
// 完成具体的任务操作 import java.util.TimerTask ; import java.util.Date ; import java.text.SimpleDateFormat ...
- 吴裕雄--天生自然java开发常用类库学习笔记:正则表达式
public class RegexDemo01{ public static void main(String args[]){ String str = "1234567890" ...
- 吴裕雄--天生自然java开发常用类库学习笔记:观察者设计模式
import java.util.* ; class House extends Observable{ // 表示房子可以被观察 private float price ;// 价钱 public ...
- 吴裕雄--天生自然java开发常用类库学习笔记:比较器
class Student implements Comparable<Student> { // 指定类型为Student private String name ; private i ...
- 吴裕雄--天生自然java开发常用类库学习笔记:Arrays
import java.util.* ; public class ArraysDemo{ public static void main(String arg[]){ int temp[] = {3 ...
- 吴裕雄--天生自然java开发常用类库学习笔记:大数操作
import java.math.* ; class MyMath{ public static double add(double d1,double d2){ // 进行加法计算 BigDecim ...
- 吴裕雄--天生自然java开发常用类库学习笔记:NumberFormat
import java.text.* ; public class NumberFormatDemo01{ public static void main(String args[]){ Number ...
- 吴裕雄--天生自然java开发常用类库学习笔记:Math与Random类
public class MathDemo01{ public static void main(String args[]){ // Math类中的方法都是静态方法,直接使用“类.方法名称()”的形 ...
- 吴裕雄--天生自然java开发常用类库学习笔记:取得当前日期
import java.util.* ; // 导入需要的工具包 class DateTime{ // 以后直接通过此类就可以取得日期时间 private Calendar calendar = nu ...
- 吴裕雄--天生自然java开发常用类库学习笔记:日期操作类DataFormat、SimpleDataFormat
import java.text.DateFormat ; import java.util.Date ; public class DateDemo03{ public static void ma ...
随机推荐
- log4j 日志配置
参考:https://blog.csdn.net/x6582026/article/details/52179817/ 1.引入jar包 log4j-1.2.17.jar log4j-core-2.1 ...
- 学习笔记(13)- decaNLP训练WikiSQL
将自然语言转为sql语句,达到对话查询报表的效果. 参考资料 参考1 https://mp.weixin.qq.com/s/i7WAFjQHK1NGVACR8x3v0A 语义解析.SQL查询生成与语义 ...
- C++获取驱动盘句柄
转载:https://www.cnblogs.com/sherlock-merlin/p/10792116.html https://univasity.iteye.com/blog/8052 ...
- uniapp - 导航切换(样式)
<view class="text-area" v-for="(menu,i) in menus" :key="i" v-show=& ...
- error C2664: “FILE *fopen(const char *,const char *)”: 无法将参数 1 从“LPCTSTR”转换为“const char *”
遇到这个问题,请打开本项目的Properties(属性)-------> Configuration Properties(配置属性)-------->General(常规)------- ...
- mysql定时删除当前时间前分钟的数据
mysql定时删除当前时间前分钟的数据 2013-01-31 0个评论 作者:上官车月 收藏 我要投稿 mysql定时删除当前时间前分钟的数据 Sql代码 www.2 ...
- 第1节 storm编程:9、storm与kafka的整合
详见代码. 下图,为设置kafka的首次消费策略,即首次消费的偏移量的示例:
- ROS学习笔记1-引言
该学习笔记参考ROS官方wiki的内容,见:http://wiki.ros.org/ROS/Introduction 什么是ROSROS的全称是Robot Operating System,即机器人操 ...
- json序列化(重要)
(1)同(2)public JsonResult JsonUserGet() { DataSet ds = Web_User.P_LG_User_Get(nUserId); return Json(J ...
- hibernate中简单的增删改查
项目的整体结构如下 1.配置文件 hibernate.cfg.xml <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hi ...