user246114
user246114

Reputation: 51601

Get a List from a Map?

How can I get a HashMap to a List? Something like:

Map<String, Horse> horses = new HashMap<String, Horse>();

ArrayList<Horse> = horses.toArray();

?

Thanks

Upvotes: 2

Views: 145

Answers (2)

Peter Tillemans
Peter Tillemans

Reputation: 35331

List<Horses> = new ArrayList<Horses>(horses.values());

horses.values() returns a Collection, if that is also fine you can skip the creation of the ArrayList.

Upvotes: 2

sanity
sanity

Reputation: 35772

List<Horse> horsesAsList = new ArrayList<Horse>(horses.values());

Upvotes: 4

Related Questions