473,658 Members | 2,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HashCode ?

22 New Member
Expand|Select|Wrap|Line Numbers
  1. public static void main(String args[]) {    
  2.         String elements[] = { "A", "B", "C", "D", "E" };
  3.         Integer l[] = {1,2,68};
  4.         Integer y=1;
  5.         int d=0;
  6.         for(int i=0;i<l.length;i++)
  7.             System.out.println(l[i]);
  8.  
  9.         Set set = new HashSet(Arrays.asList(elements));
  10. //        set.addAll(Arrays.asList(l));
  11.         set.addAll(Arrays.asList(l));
  12.         set.add(y);
  13.         set.add(d);
  14.     System.out.println(elements);
  15.  
  16.         Iterator itr=set.iterator();
  17.  
  18.     while(itr.hasNext())    {
  19.         Object hs=itr.next();
  20.         System.out.println("Value : "+hs+"\t Hash Code :"+hs.hashCode());
  21.         //System.out.println("Value : "+itr.next()+" Hash Code :"+itr.hashCode());
  22.         }
  23.         Set set2 =((Set) ((HashSet) set).clone());
  24.         System.out.println("Hash Code :"+set.hashCode());
  25.         System.out.println("Hash Code :"+set2.hashCode());
  26.         System.out.println(set2);    
  27.       }    
This is my program...
So my problem is for every object there should be a uniq hasCode isn't it. But i'm getting some same hashCode for some different objects.
Like....
[Ljava.lang.Stri ng;@10b62c9
Value : 68 Hash Code :68
Value : 2 Hash Code :2
Value : D Hash Code :68
Value : A Hash Code :65
Value : 1 Hash Code :1
Value : C Hash Code :67
Value : B Hash Code :66
Value : 0 Hash Code :0
Value : E Hash Code :69
Hash Code :406
Hash Code :406
[D, 2, 68, A, C, 1, B, E, 0]


Help me out!
Oct 11 '07 #1
1 1676
JosAH
11,448 Recognized Expert MVP
Help me out!
Hash codes need not be unique but if two hash codes are not equal you can be
sure that you're dealing with two different objects.

kind regards,

Jos
Oct 11 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
6804
by: pentium77 | last post by:
Hi, Just wondering what's the algo used to compute hashcode in Java ? Does anybody here know ? Thanks, -MK.
4
3910
by: Nick | last post by:
Hi all, I am using GetHashCode on unique strings to get a unique integer for a string that I can then place into a database (use int rather than the string to make indexing faster). The problem is that the hashcode can change depending ion the clr version, from msdn 'The behavior of GetHashCode is dependent on its implementation, which might change from one version of the common language runtime to another. A reason why this might happen...
3
8491
by: Josema | last post by:
Hi to all, In a lot of type of classes in the .net framework classes library i see that has the method GethashCode. What is the HashCode of anything, and in wich kind of functionality are used for? --
1
1711
by: Frank | last post by:
Hi, I save the hashcode of a datatablerow. How do I use that hascode to get to the original datarow? Thanks Frank
8
3538
by: MuZZy | last post by:
Hi, Why for god sake they change implementation of String.GetHashCode() from ..NET 1 to .NET 2? We were storing some user passwords in hashcode, now we can't upgrade those clients with .NET 2 vesrion of our app as they will not be able to log in. I know, we shouldn't have dealt with hashcode in the first place, but we
9
2086
by: archana | last post by:
Hi all, I have one question regarding hashing in .net I have two string containing same data. When i see hashcode by calling gethascode, i am getting same value. I want to know how internally strings are storing using hasing. Please clear my concept regarding hashing in ,net
1
3995
by: Ing. Davide Piras | last post by:
Hi there, I really don't know if I can post here or microsoft.public.dotnet.framework.adonet could be better... anyway: in my .NET 2.0 C# arcitecture (windows form as client application, web application/web services as server), I have some methods that retrieve datasets from web service, then i save them locally with WriteXML and I can work offline, making insert, update and delete... then I connect again and I send only the changed rows...
11
2310
madhoriya22
by: madhoriya22 | last post by:
Hi, I have wrapped to strings in a object using hashCode of these strings.......Now I want to know how can I get back these strings from the object...............I am putting this object as a key in a HashMap.....For more details kindly look here
10
105177
by: r035198x | last post by:
The Object class has five non final methods namely equals, hashCode, toString, clone, and finalize. These were designed to be overridden according to specific general contracts. Other classes that make use of these methods assume that the methods obey these contracts so it is necessary to ensure that if your classes override these methods, they do so correctly. In this article I'll take a look at the equals and hashCode methods. ...
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8850
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8626
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6178
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.