dimanche 13 novembre 2016

How to assign random numbers (0-10) to strings stored in a linkedlist

I am as the title states I am having trouble assigning random number values to string stored in a linkedlist. Here is my linkedlist:

List genres = new LinkedList<>();

     attributes.add("Action");
     attributes.add("Comedy");
     attributes.add("Documentary"); 
     attributes.add("Romance");
     attributes.add("Drama"); 

I came up with something like this, but I realised it is for an array and not linkedlist:

Random ran = new Random();

String genres_ran = genres[ran.nextInt(genres.length)];

I greatly appreciate any help, many thanks!




Aucun commentaire:

Enregistrer un commentaire