- public static void main(String args[]) {
-
String elements[] = { "A", "B", "C", "D", "E" };
-
Integer l[] = {1,2,68};
-
Integer y=1;
-
int d=0;
-
for(int i=0;i<l.length;i++)
-
System.out.println(l[i]);
-
-
Set set = new HashSet(Arrays.asList(elements));
-
// set.addAll(Arrays.asList(l));
-
set.addAll(Arrays.asList(l));
-
set.add(y);
-
set.add(d);
-
System.out.println(elements);
-
-
Iterator itr=set.iterator();
-
-
while(itr.hasNext()) {
-
Object hs=itr.next();
-
System.out.println("Value : "+hs+"\t Hash Code :"+hs.hashCode());
-
//System.out.println("Value : "+itr.next()+" Hash Code :"+itr.hashCode());
-
}
-
Set set2 =((Set) ((HashSet) set).clone());
-
System.out.println("Hash Code :"+set.hashCode());
-
System.out.println("Hash Code :"+set2.hashCode());
-
System.out.println(set2);
-
}
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!
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: pentium77 |
last post by:
Hi,
Just wondering what's the algo used to compute hashcode in Java ? Does
anybody here know ?
Thanks,
-MK.
|
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...
|
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?
--
|
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
|
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
| |
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
|
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...
|
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
|
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.
...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |