简体   繁体   中英

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

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

horses.values()返回一个Collection ,如果还可以,则可以跳过ArrayList的创建。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM