Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Map/HashMap

Posted on 2011-02-11
1
Medium Priority
?
473 Views
Last Modified: 2012-05-11
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?


0
Comment
Question by:allelopath
1 Comment
 
LVL 5

Accepted Solution

by:
aciuica earned 2000 total points
ID: 34873528
I you really know that there is one value you can try:
MyClass value = myMap.values().iterator().next();
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question