-4

I would be pleasure if you can suggest. Could you suggest how properlly I can retriev all values from hashmap. In such simplee example:

    Map<String, Values> someMap = ....;
    List<Values> valuesFromMap = (List<Values>) someMap.values(); 

After that I've got that, Java couldn't cast to java.util.List

Thank you in advanced.

0

2 Answers 2

3

The values method returns a Collection, not a List. Use

Collection<Values> valuesFromMap = someMap.values(); 
Sign up to request clarification or add additional context in comments.

Comments

1

someMap.values() returns Collection. If you need to convert into List than do that as follows:

 List<Values> valuesFromMap = new ArrayList<>(someMap.values()); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.