java


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<String> 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!
If you want to assign random numbers to strings, use a Map data structure.
However, looking at your attempt, it seems you want a random member from the List. Do this:
String randomGenre = genres.get(new Random().nextInt(genres.size()));

Related Links

Java-Chars can rotate left but can't rotate to the right?
Http Status 500 returned on Spring MVC Using REST Templates and JSON Response Format
Design Patterns: Callback as a method parameter
Java - How to encrypt passwords for wordpress? [duplicate]
How can i post and return a value in a Webservice?
Codility FrogJmp strange Java score
Eclipse Advanced code template
Android Parcelable: How to read / write string array lists and integer arrays
Duplication on ArrayList Java
Is it okay to use Thread.sleep as a timer in a console application?
Post form from java backend and redirect to it [closed]
eclispe : An internal error occurred during: “Updating Maven Project” java.lang.StackOverflowError
dependency issue for net unicorn and ojdbc14
How to create dynamic columns in ireport?
How to remove status 203 error in parsing Google-trends html response?
Does Java use AES-NI when available?

Categories

HOME
cakephp
wso2
mockito
filtering
paw-app
amortized-analysis
microservices
qore
android-youtube-api
rascal
zend-framework3
apache-cayenne
jplayer
gz
commonmark
decimal
percona
iolanguage
contextmenu
clickonce
zurb-foundation-6
devops
user-interaction
greendao
linkerd
minitab
jaxb2
windows-server-2000
libuv
libssl
subdomains
c++-amp
nouislider
microsoft-chart-controls
winrt-xaml-toolkit
geopositioning
suricata
hockeyapp
serverside-rendering
sharefile
reportbuilder
particles.js
mapzen
sql-server-agent
pdf-reactor
elmah
no-www
angular2-meteor
multipeer-connectivity
directory-structure
lift-json
typed-lambda-calculus
memory-alignment
dwscript
redundancy
blacklist
azure-sdk
url-masking
skobbler-maps
bstr
pickadate
ipconfig
browser-link
python-3.2
wyam
rgeo
muse
ami
composite
web-controls
javax.mail
android-imagebutton
wordpress-theme-customize
websocket4net
code-access-security
uitouch
valueconverter
prettify
tidy
opcache
gridcontrol
rabl
hungarian-algorithm
jquery-mobile-dialog
cassini-dev
mt
gdata-api
manchester-syntax
buildr
mercurial-server
stage
hamachi
xdomainrequest
javax.script
gdlib
html-input
visitor-statistic
cxxtest
sproutcore-2
compiler-specific
putchar
mediarss
scripting-languages
mdac
signal-handling
uiq3

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App