Solved

Map/HashMap

Posted on 2011-02-11
1
426 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 500 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
copyEndy  challenge 15 58
scoreUp challenge 14 48
how to use external config file with Spring MVC 4 63
eclipse formatting 6 43
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now