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


i title states having trouble assigning random number values string stored in linkedlist. here linkedlist:

list<string> genres = new linkedlist<>();            attributes.add("action");          attributes.add("comedy");          attributes.add("documentary");           attributes.add("romance");          attributes.add("drama");  

i came this, realised array , not linkedlist:

random ran = new random();   string genres_ran = genres[ran.nextint(genres.length)]; 

i appreciate help, many thanks!

if want assign random numbers strings, use map data structure.

however, looking @ attempt, seems want random member list. this:

string randomgenre = genres.get(new random().nextint(genres.size())); 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -