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()));
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?