---
title: "ArrayList from HashMap values"
author: "cai555"
date: "2010-10-09T14:47:12Z"
tags: []
categories: ["编程语言"]
slug: "arraylist-from-hashmap-values"
draft: false
lastmod: "2010-10-09T14:47:12Z"
id: 779570
url: "https://cai555.iteye.com/blog/779570"
---

Is there a way to cast HashMap values to an ArrayList or do I have use the iterator? HashMap.values() returns a Collection and I thought i could cast it to an ArrayList but I get a ClassCastException.

 

是否有办法将HashMap转化为ArrayList?如果直接将HashMap.values() 强制转化为ArrayList 会报ClassCastException。

 

解决办法：

 

```
List myList = new ArrayList(myHashMap.values());
```