-5

I am practicing learning java and I would like to learn a lot more than I can find on my own hence I am asking this question. I know how to create a hashmap, I know how to add things into the hashmap, I would like to know how I add an object called "Timmy" into one side of the hashmap and then add an integer that grows every second by 1 into the other side. Once it has reached lets say 400 it will do something like add "Timmy" into another hashmap, and then into another hashmap... If you understand what I am saying. I would also like to know how to do something once they have joined the next tier hashmap.

Here is an example of what I mean:

Timmy joins 1st hashmap > Waits 400 seconds > Gets promoted to next hashmap > Console.log("You have reached the second hashmap!") > Waits 800 seconds this time> Gets promoted into the third hashmap > Console.log("You Win, by advancing through all the hashmaps.").

I will come back when all attempts fail, I am sorry that I presented my question like this. I understand that it was rude of me not to fully evaluate what my question is trying to get an answer for.

Shaden
  • 3
  • 3
  • 2
    What's the rationale for doing this? It seems like an overcomplicated way to achieve whatever you're trying. – chrylis -cautiouslyoptimistic- Apr 08 '18 at 07:06
  • *"add [...] "Timmy" into one side [...] and then add an integer [...] into the other side"*. `HashMap` doesn't have "sides". It consists of key/value pairs. Is "Timmy" the **key** or the **value**. I mean, I know it's the "one" side, but which is which? Is **key** the *one* or the *other*? – Andreas Apr 08 '18 at 07:36

1 Answers1

0

You could do something like the following:

int total = 100;
int i = 0;

// You should use a more specifc type than Object if you can
Map<Integer, Object> m = new HashMap<Integer, Object>();

while (i < total) {

    Object o = //what you want to put into the HashMap on each iteration

    m.put(i, o);

    Thread.sleep(1000);
    i++;
}

Hope this helps!!! :D

CarManuel
  • 325
  • 3
  • 12