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
Post a Comment