hashcode

hashCode() value changes between executions

不羁岁月 提交于 2019-12-23 12:23:06
问题 hashCode of an object has to be consistent for that object throughout one execution of the application-- for any object o, o.hashCode() should return the same int value. However, this doesn't have to be from one run-time to another: o.hashCode() can return some other value and this is perfectly alright by the specs. HashMap calculates the right bucked based on the hashCode value. My Q is: how is this value change between one session to another handled? Does serialization have features to

浅谈集合框架一、概念

不想你离开。 提交于 2019-12-23 11:46:36
  最近刚学完集合框架,想把自己的一些学习笔记与想法整理一下,所以本篇博客或许会有一些内容写的不严谨或者不正确,还请大神指出。初学者对于本篇博客只建议作为参考,欢迎留言共同学习。   本篇为介绍集合框架的体系及概念,具体使用方法请看下一篇( http://www.cnblogs.com/yjboke/p/8777629.html )。 集合定义:java集合类就是一种工具类,就像是一个容器,可以存储任意数量的对象。 与数组的区别:1、长度:数组的长度是固定的,集合的长度不是固定的,可以任意增减。  2、访问方式:数组只能通过int类型下标获取元素,集合可通过任意类型映射获取对象。  3、存储类型:数组只可以存储一种类型,集合可存放多种类型(如果不加泛型的话)。 集合框架:在实际运用中,根据不同的需求,有了更多的不同数据结构的容器(不同类型的集合),在不断向上抽取的过程中形成了一个体系,也就是集合框架。 设计: 两大基类Collection和Map(最顶层的两个接口) 区别: Collection表示的是一组纯数据。   Collection主要有三个子接口: List:元素是有序的,允许有重复元素的集合,改集合体系有索引; ArrayList:底层的数据结构使用的是数组结构。 特点:查询快,增删慢,线程不同步。 LinkedList:底层使用的链表数据结构。 特点:增删快,查询慢

----------------------集合-------------------------

做~自己de王妃 提交于 2019-12-23 11:44:30
1:集合:存储对象 遍历取出对象 List<要存储元素的数据类型> 变量名 = new ArrayList<要存储元素的数据类型>(); 必须要引用数据类型,不能是基本类型,除非把基本数据类型变成包装类 b:集合 * b1:集合的层次结构 * Iterable <E> 实现了Iterable接口的集合类才可以被foreach * Collection 接口 集合最顶层的接口 * List 接口特点: 有序 有索引 可以重复元素 元素存与取的顺序相同 泛型用来约束集合中可有存储的数据类型 * ArrayList 底层是数组 根据索引查询,增删慢 ArrayList是实现了基于动态数组的数据结构 寻址容易,插入和删除困难; * LinkedList 底层是链表 增删快 查询慢 LinkedList是基于链表的数据结构 寻址困难,插入和删除容易。 子类特有的功能,不能多态调用 * Stack 栈结构的集合 stack继承vector其底层用的还是数组存储方式 Stack 栈结构的集合 官方建议:使用栈尽量使用ArrayDeque: Deque 接口及其实现提供了 LIFO 堆栈操作的更完整和更一致的 set,应该优先使用此 set,而非此类。例如: Deque stack = new ArrayDeque(); * Vector 线程安全的线性集合 *

Why is there a need to override hashcode if I override the 'equals' method in Java?

谁都会走 提交于 2019-12-23 09:34:46
问题 I know there is a need to override hashcode whenever the equals method is overridden in Java. That is merely a contract. I am trying to understand the logic behind this. I was reading *Effective Java by Joshua Bloch, and I came across this code (Item 9, page 45): import java.util.HashMap; import java.util.Map; public final class PhoneNumber { private final short areaCode; private final short prefix; private final short lineNumber; public PhoneNumber(int areaCode, int prefix, int lineNumber) {

Java中常见数据结构:list与map

北慕城南 提交于 2019-12-23 07:56:55
1 1:集合 2 Collection(单列集合) 3 List(有序,可重复) 4 ArrayList 5 底层数据结构是数组,查询快,增删慢 6 线程不安全,效率高 7 Vector 8 底层数据结构是数组,查询快,增删慢 9 线程安全,效率低 10 LinkedList 11 底层数据结构是链表,查询慢,增删快 12 线程不安全,效率高 13 Set(无序,唯一) 14 HashSet 15 底层数据结构是哈希表。 16 哈希表依赖两个方法:hashCode()和equals() 17 执行顺序: 18 首先判断hashCode()值是否相同 19 是:继续执行equals(),看其返回值 20 是true:说明元素重复,不添加 21 是false:就直接添加到集合 22 否:就直接添加到集合 23 最终: 24 自动生成hashCode()和equals()即可 25 26 LinkedHashSet 27 底层数据结构由链表和哈希表组成。 28 由链表保证元素有序。 29 由哈希表保证元素唯一。 30 TreeSet 31 底层数据结构是红黑树。(是一种自平衡的二叉树) 32 如何保证元素唯一性呢? 33 根据比较的返回值是否是0来决定 34 如何保证元素的排序呢? 35 两种方式 36 自然排序(元素具备比较性) 37 让元素所属的类实现Comparable接口 38

【java基础之jdk源码】Object

回眸只為那壹抹淺笑 提交于 2019-12-23 05:29:27
最新在整体回归下java基础薄弱环节,以下为自己整理笔记,若有理解错误,请批评指正,谢谢。 java.lang.Object为java所有类的基类,所以一般的类都可用重写或直接使用Object下方法,以下为逻辑结构图,没有画类图 (注: 以上 绿色 方法为 非native方法 粉色 方法为 native方法) 那么问题来了 : 1、what is a native object?   本人理解: native关键字标识的java方法为本地方法,底层是有c/c++编写的程序编译后dll文件,java加载dll文件后,         可用通过本地方法调用dll中函数,如有疑问可用参考JNI使用方式,看参考:http://blog.csdn.net/yangjiali014/article/details/1633017         以下为Object类对应openjdk\jdk\src\share\native\java\lang\Object.c的源码 片段1 : 1 static JNINativeMethod methods[] = { 2 {"hashCode", "()I", (void *)&JVM_IHashCode}, 3 {"wait", "(J)V", (void *)&JVM_MonitorWait}, 4 {"notify", "()V", (void *

Magento password hash in Customer info

廉价感情. 提交于 2019-12-23 03:16:05
问题 Hi every body i try to check passwords of users of magento store , i get password from user and magento and try to compare them , one of them is hash code and other is normal string , i want to generate hash of normal one and compare them but problem is magento hashed password is different ! this is password : 123456 and this is hash that i get from magento : 2364b70e91268d8ecf59fffd47db692b:LSC2VzugdDdUbghTHoTouZeMLxk14OPT and this is md5 hash i generate for 123456 :

overriding equals and hashcode methods in java?

ぐ巨炮叔叔 提交于 2019-12-23 03:09:23
问题 I have below class. Request.java public class Request implements Serializable { private String id; private String name; private String hid; // getters and setters // This class does not override any equals() and hashCode() methods } public class EmpRequest implements Serializable { private Request request; //Now here in this class I need override equals() and hashCode() methods based on **request** } In EmpRequest class, I need to override equals() and hashCode() based on properties of

How to obtain the same result of Java String.hashCode() in Objective-C?

蹲街弑〆低调 提交于 2019-12-23 02:38:45
问题 I've been reading documentation about String.hashCode() on http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/lang/String.java Trying obtain an identical result from an identical string, but I did not come up with any satisfying results. In Objective-C [NSString hash] gives a totally different result. Have anyone already done this? Thanks 回答1: The answer provided by Alfred is not correct. First of all, hashCode can return negative, so the return type should be a

C++ what can make type_info::hash_code differs for two (supposedly) same objects

纵饮孤独 提交于 2019-12-22 14:42:10
问题 After trying to debug an unsuccessful dynamic downcasting, I eventually found that the reason probably is: type_info::hash_code for the type it is casted to is not the same depending where in the code it is called. type_info::name stays exactly the same though. Unfortunately I'm unable to reproduce the behavior in a minimal example since it appears in a quite entangled context. Therefore I'm essentially looking for clues of what can be the cause of such behavior, and consequently what