List<HotAndNEwData> result = response.results;
List<HotAndNEwData> pastYear = result;
pastYear.shuffle();
List<HotAndNEwData> trending = result;
trending.shuffle();
List<HotAndNEwData> southIndian = result;
southIndian.shuffle();
List<HotAndNEwData> dramas = result;
dramas.shuffle();
I need to get 4 different lists, but at end of this code I get the same list in all variables, please suggest a solution for this
CodePudding user response:
You get the same list in all variables because it does not do a copy but only creates a refereces.
You have to make a copy of the list. I believe this should help you https://stackoverflow.com/a/21744481/3146225
So it would look something like this:
List<HotAndNEwData> pastYear = List.of(result);
pastYear.shuffle();
List<HotAndNEwData> trending = List.of(result);
trending.shuffle();
List<HotAndNEwData> southIndian = List.of(result);
southIndian.shuffle();
List<HotAndNEwData> dramas = List.of(result);
dramas.shuffle();