Bookmark Topic Watch Topic
  • New Topic

Help me with shuffle in list.  RSS feed

 
Erdene Yadam
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Report post to moderator
I have a problem with my code.
Every men and women have same preference list on output.
They all should have different preference list. why collections.shuffle is not shuffling it? it shuffles it only once. i dont understand why

they all have same preference list. men and women
I want every preference list to be shuffled
Output:
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Report post to moderator
because you are storing same object in each index of map. So, when you shuffled the same object again then values in all index in map also updated.

And you will get last shuffled value in all the indices.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
This is a duplicate of this topic of...

https://coderanch.com/t/670802/java/java/HashMap

And the OP got the answer on that one too.


To the OP ... Please stop creating duplicate topics. This causes duplicate effort.

Henry
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!