在Java中打破了一倍 [英] Hash a double in Java

查看:165
本文介绍了在Java中打破了一倍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在Java中哈希一个双引号?我已经混合了其他原始数据和对象。我以为可以使用hashcode方法?从我看过的这个看起来相当复杂。我遇到了一些关于创造种子的事情。



我想知道有关如何解决这个问题的任何想法。希望放弃我的哈希码的其余部分,这个类有两个?



我想知道是否有问题,我试图排列数组列表,数组和其他java中的对象我的一些类包含数组列表。



非常感谢

解决方案

a href =http://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#hashCode%28%29> Double.hashCode() 复杂?它基本上将 double 转换为 long (这里没有魔法,毕竟他们都只是内存中的64位值)和计算 long 哈希很简单。 double - > long 转换是通过 public static doubleToLongBits() 。什么是复杂的?



示例:



  Double.valueOf (42.5).hashCode(); //更好地回答一切

Long.valueOf(Double.doubleToLongBits(42.5))。hashCode();


I was wondering how to hash a double in Java? I have hashed other primitive data and objects. I thought I could use the hashcode method? From what I have seen this looks quite complex. I came across something about creating a seed.

I was wondering any ideas on how to go about this. Hoping to put in with the rest of my hashcode for the class that has the double?

I was wondering if there are issues with me trying to hash arraylists, arrays and other objects in java. Some of my classes contain arraylists.

Many Thanks

解决方案

Double.hashCode() complex? It basically converts double into a long (no magic here, after all they both are simply 64-bit values in memory) and computing long hash is quite simple. The double -> long conversion is done via public static doubleToLongBits(). What is complex about this?

Examples:

Double.valueOf(42.5).hashCode();        //better answer to everything

Long.valueOf(Double.doubleToLongBits(42.5)).hashCode();

这篇关于在Java中打破了一倍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆