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:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
Wrappers with String and Collections
Sekhar Choudary
Ranch Hand
Posts: 57
posted 15 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: 23951
142
I like...
posted 15 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)
PI day is 3.14 (march 14th) and is also einstein's birthday. And this is merely a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
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...