-1

my code loook at the out put

i want to iterate through the has map in java. i am not able to get the keys from my code. it gives me random kind of keys that's not what i want. my keys are of class type.

i have tried many things but i don't know exactly how can i get the keys . i can get the keys when i have the keys of primitive or wrapper classes type but not when i am entering a key from user defined class.

Suryakant Bharti
  • 673
  • 1
  • 6
  • 24
  • 1
    Does this answer your question? [How do I print my Java object without getting "SomeType@2f92e0f4"?](https://stackoverflow.com/questions/29140402/how-do-i-print-my-java-object-without-getting-sometype2f92e0f4) – OH GOD SPIDERS Jan 30 '20 at 10:54
  • The code already gets your keys, you simply don't know how to print them properly. – OH GOD SPIDERS Jan 30 '20 at 10:54
  • 'random kind of keys' is actually the combination of class name & hashcode of the objects t1, t2 ,etc. – Smile Jan 30 '20 at 10:55
  • 1
    In the future, please don't post pictures of your code and output, but post them as text instead. It's much easier to answer in that case. – Joachim Sauer Jan 30 '20 at 11:06

1 Answers1

0

Iterating through HashMap in Java printing all keys and values together:

    map.forEach((key, value) -> {
            System.out.println(key + " " + value);
        });

Note: we are using the forEach lambda expression, which needs Java 8, but it is very clear & concise.

Suryakant Bharti
  • 673
  • 1
  • 6
  • 24