Java 将自定义的对象作为HashMap的key
来源:互联网 发布:ubuntu cpuz 编辑:程序博客网 时间:2024/05/29 16:04
需要继承Map的equals函数和hashCode函数
package com.category;import java.util.HashMap;public class GenCategoryLevelData {private static HashMap<Category, Integer> categoryLevel = new HashMap<Category, Integer>();/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stub}/** * 分类 * @author ouyangyewei * */public static class Category {public long categoryId;public String categoryName;@Overridepublic boolean equals(Object obj) {Category category = (Category)obj;return (this.categoryId==category.categoryId&& this.categoryName.equals(category.categoryName));}@Overridepublic final int hashCode() { int hashCode = 17; hashCode = hashCode * 31 + 1; hashCode = hashCode * 31 + 1; return hashCode; }public Category() {// empty}public Category(long categoryId, String categoryName) {this.categoryId = categoryId;this.categoryName = categoryName;}public long getCategoryId() {return categoryId;}public void setCategoryId(long categoryId) {this.categoryId = categoryId;}public String getCategoryName() {return categoryName;}public void setCategoryName(String categoryName) {this.categoryName = categoryName;}}}
2 0
- Java 将自定义的对象作为HashMap的key
- Java 自定义类作为HashMap的key
- Java用自定义的类作为HashMap的key值
- Java用自定义的类型作为HashMap的key
- equals和==的区别,以及如何将自定义类作为HashMap的Key
- HashCode 和 Equals 的使用 - 使用自定义对象作为HashMap的Key例子
- java HashMap用自定义类作为key
- java HashMap用自定义类作为key
- 自定义枚举类 Enum 是否可以作为 HashMap 的key
- 用自定义的对象作为Map的key
- HashMap使用对象作为key
- 自定义对象作为NSDictionary key的一些问题
- python--用户自定义类对象作为dict的key
- 空字符串可以作为HashMap的key
- 使用一个类作为hashMap的key
- 谨慎使用String作为HashMap的Key
- 谨慎使用String作为HashMap的Key
- 谨慎使用String作为HashMap的Key
- c 哈希学习
- oracle 主键删除,联合主键的创建
- AFNetWorking2.0
- 星际争霸2编辑器的初接触
- android 百度音乐搜索地址
- Java 将自定义的对象作为HashMap的key
- c 基础学习
- poj 1067 取石子游戏
- C预处理指令
- 1407231901-hd-Problem C.cpp
- 块设备驱动程序<一>
- 相位技术的实现
- win7在64位系统下编译openssl
- iOS项目的目录结构和开发流程