Map/HashMap

Suppose I have a Map:
Map<String, MyClass> myMap = new HashMap<String, MyClass>();

I know there is only 1 key/value pair in it. I don't know or care what the key is, but I want to get the value. What's the best way to do this?


LVL 1
allelopathAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
aciuicaConnect With a Mentor Commented:
I you really know that there is one value you can try:
MyClass value = myMap.values().iterator().next();
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.