With
shuffledPlaylist = unshuffledPlaylist;
you are not creating copy of original list, but you are making shuffledPlaylist
reference to hold same list as unshuffledPlaylist
so in the end they both hold same list. That is why each modification done via one of these references is visible via other reference.
To create separate list based on original list you can use copying constructor
shuffledPlaylist = new ArrayList(unshuffledPlaylist);
Collections.shuffle(shuffledPlaylist);//now you can shuffle copy of original list
Also to check if two List
(or any object) instances are equal (have same state) don't use X==Y
because ==
just checks if references X
and Y
hold same object (like in your case). Instead you should use X.equals(Y)
method.