Read carefully before marking duplicate or downvoting.
My Requirement is to shuffle Arraylist of object keeping the list data same just changing the position. I have an of type Dummydata :
List<DummyData> dataList = new ArrayList<>();
My DummyData class has three String fields.
So adding some data for clarification:
dataList.add(new DummyData("Item1","Price1","Discount1"));
dataList.add(new DummyData("Item2","Price2","Discount2"));
dataList.add(new DummyData("Item3","Price3","Discount3"));
dataList.add(new DummyData("Item4","Price4","Discount4"));
dataList.add(new DummyData("Item5","Price5","Discount5"));
When I use Collections.shuffle(dataList);
the output is :
Item5 Price3 Discount4
Item2 Price1 Discount2
and some random output like this everytime.
My intended output is :
Item2 Price2 Discount2
Item5 Price5 Discount5
Item1 Price1 Discount1
Just the position should change list data should not jumble. so my question is this possible to achieve using Collections.shuffle or not??