Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
Programmer Certification (OCPJP)
Wrappers with String and Collections
Sekhar Choudary
Ranch Hand
Posts: 57
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import java.util.*; public class CollWrapperEX{ private String s; public CollWrapperEX(String s){ this.s=s; } public static void main(String[] args){ HashSet<Object> hs=new HashSet<Object>(); CollWrapperEX ws1=new CollWrapperEX("xyz"); CollWrapperEX ws2=new CollWrapperEX("xyz"); String s1=new String("xyz"); String s2=new String("xyz"); hs.add(ws1);hs.add(ws2);hs.add(s1);hs.add(s2); } }
I am getting the size as 3
Can anyone expalin this.
Thanks
Henry Wong
author
Posts: 23959
142
I like...
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
To understand why this is so, you need to understand hashing. And since you asked about hashing here...
https://coderanch.com/t/269877/java-programmer-SCJP/certification/Help-hashcodes
I think it is best if you undertand that first.
Henry
Books:
Java Threads, 3rd Edition
,
Jini in a Nutshell
, and
Java Gems (contributor)
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
I am finding hashing a bit confusing please it in a bit detail
HashSet Duplicate element ?
Hashcodes in hashset
More...