A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Java in General
Joined: Mar 22, 2011
May 17, 2011 18:51:11
I've created a Hashmap like the following
> myMap = new
I've added my keys and values, and I understand how to do a straight iteration through my
, but how do I access only the "5th" item in the
(just as an example).
So I know the 5th item in the
for each of the hashmap values will be a phone number, I want to iterate through the
and only grab that 5th value.
Joined: Jan 09, 2008
May 17, 2011 19:01:58
Eugene: As you described, you first get the keySet() of your Map and then
using for(each), iterate through this Set, get() each List and pick up its 5th element.
BEE MBA PMP SCJP-6
Joined: Oct 13, 2005
May 18, 2011 15:07:50
. . . which will of course throw a
if the name "Eugene" doesn't appear as a "key".
But you have a serious design problem. Why on earth is the phone number the 5th item in the List? Why haven't you created a class to encapsulate all those values?
I agree. Here's the link:
subject: HashMap<String, ArrayList>
Struts2: Retern all the values inside the list in my Action
Getting a single name from an arraylist...
Adding values to a list already against already existing key in HashMap
Adding key/value pairs from a HashMap in to an ArrayList
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015