Skip to content
Advertisement

How to get certain values from ArrayList and put them in a map

I have a program where there are 52 cards and int number of players (for example lets start from 4), the task is asking me to put elements like this in a map of Map<String, List>:

JavaScript

I have written the logic like this:

JavaScript

Any suggestions how to put those List in the map according to the task?

Advertisement

Answer

Since cannot figure out what exactly is needed, maybe this could be helpful.

JavaScript

Output:

JavaScript

Note: Construct player_n list can be optimized with

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement