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.