0
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

1 Answers1

0

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();
Lukasas
  • 139
  • 8
  • thanks bro... like this also working... List result = response.results; List pastYear =result.toList(); pastYear.shuffle(); List trending = result.toList(); trending.shuffle(); List southIndian = result.toList(); southIndian.shuffle(); List dramas = result.toList(); dramas.shuffle(); – Mohamed Shafeeq Jul 12 '22 at 14:54