-2

I have my HashMap as below:

Map<String, List<Double>> map = new HashMap<String, List<Double>>();//map
Iterator<java.util.Map.Entry<String, List<Double>>> iterator = map.entrySet().iterator();
List<Double> times = new ArrayList<Double>();//arraylist

There is a String as a key and two double values. What I want to do is when I call the key I want to assign those two double values individually into two double variables.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Sankalpa Wijewickrama
  • 985
  • 3
  • 19
  • 30
  • *I expect some code examples.* What is this, a test? – shmosel Jan 22 '17 at 06:42
  • Actually the whole code is so big, that is why i didn't copy the whole thing.... – Sankalpa Wijewickrama Jan 22 '17 at 07:03
  • 1
    What are you stuck on? Do you know how to get a value from a map? Do you know how to get a value from a list? Both are extremely basic tasks and can easily be answered with a quick search. – shmosel Jan 22 '17 at 07:05
  • Yeah ! I got it now ! Thanks. – Sankalpa Wijewickrama Jan 22 '17 at 11:18
  • I expect you to stop being demanding, since you're asking for free help. When people say "I expect" something from other people, it usually sounds like a demand. Like a boss ordering someone to do something. That may not be what you thought you're saying but that's how people tend to regard it. – clearlight Jan 23 '17 at 01:08
  • I am so sorry about that. I really didn't mean to order or be like a boss. I am not English and I may don't get the idea of the word as others get it. I apologize for the inconvenience. Really sorry about that. I will remove that part from the question. Thanks – Sankalpa Wijewickrama Jan 23 '17 at 06:07

1 Answers1

2

Without any error checking (such as missing keys or malshaped List):

List<Double> times = map.get("theKey");
if(times.size() > 1){//To avoid the java.lang.ArrayIndexOutOfBoundsException
    double t1 = times.get(0);
    double t2 = times.get(1);
}
Roy Shmuli
  • 4,979
  • 1
  • 24
  • 38
Thilo
  • 257,207
  • 101
  • 511
  • 656