Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Why I Am Getting Duplicate In HashSet?

 
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My Main Set


My Temp Set


Suppose main Set contains
{{0,3}{1,2,4,5,6}}

Suppose tmp Set contains
{{5,6,8},{1,2,4,5,6}}

When I am doing



what I get in Set lists is
{{0,3},{1,2,4,5,6},{5,6,8},{1,2,4,5,6}}

So i thought why not to check their hashcode so I did


since the max size value is 5
Output is 1,2,4,5,6
1,2,4,5,6
twice which I don't want in fact I m using Set because i don't want duplicate Stack in Set lists
Where my Understanding is going wrong?
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You said yourself: "what I get in Set lists is {{0,3},{1,2,4,5,6},{5,6,8},{1,2,4,5,6}}", so why are you surprised that there are two stacks of length 5?
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply sir,

My question is Set doesn't store duplicate then how 2 stack with similar content & similar hashcode is stored in Set lists?
 
author
Posts: 23912
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

naved momin wrote:
My question is Set doesn't store duplicate then how 2 stack with similar content & similar hashcode is stored in Set lists?



Please provide an SSCCE of this issue.

Henry
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok i got it thanks for the help
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok i got it anyways thanks for the help
 
Henry Wong
author
Posts: 23912
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

naved momin wrote:
Suppose main Set contains
{{0,3}{1,2,4,5,6}}

Suppose tmp Set contains
{{5,6,8},{1,2,4,5,6}}

When I am doing



what I get in Set lists is
{{0,3},{1,2,4,5,6},{5,6,8},{1,2,4,5,6}}

Where my Understanding is going wrong?



Just tested it. And it works for me. I get this from my test program.

first set of stack: [[1, 2, 4, 5, 6], [0, 3]]
second set of stack: [[1, 2, 4, 5, 6], [5, 6, 8]]
first set of stack (after allAll()): [[1, 2, 4, 5, 6], [5, 6, 8], [0, 3]]



Henry
 
Bartender
Posts: 4731
183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That was to be expected. If you look at the 'Vector' API (a Stack extends it)
you see how the equals method is defined. Not only should the types be equal,
but the stacks must be of the same size, and for each i Q1(i) must be equal to
Q2(i).

So, Stack(1,2,3) equals Stack(1, 2, 3) but Stack(1, 2, 3) <> Stack(2, 1, 3).

Greetz,
Piet
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic