473,465 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Create 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.String;@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 1663
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
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
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...
3
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...
1
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
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...
9
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...
1
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...
11
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...
10
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.