0

I am getting a map in the form as below :

{owner=sailpoint.object.Identity@2aea717c[id=8ad616906a065639016a0657e2df000d,name=Jsmith]}

How can I get only "Jsmith" as my value to key "owner"?

thush
  • 117
  • 9
Barca Fan
  • 47
  • 3
  • 2
    What type is your key? What you want to get as result? – talex Apr 25 '19 at 07:29
  • Can you post your `HashMap` declaration? – anasmi Apr 25 '19 at 07:30
  • 1
    So your map looks something like this: `Map` and you would like a `Map`? Then you could use streams, like so: `yourMap.entrySet().stream().collect(Collectors.toMap(Entry::getKey, e -> e.getValue().getName()));` – Lino Apr 25 '19 at 07:31
  • 1
    Your output show a `Identity` instance as a value, instead, use the `name` member of that instance as a value. (and of course, change the `Map` declaration. I don't believe we can write a correct answer to this question so I would propose to close for "typo" since you use the wrong value during the population of the map. – AxelH Apr 25 '19 at 07:45
  • Following link should help you: https://stackoverflow.com/questions/22742974/in-java-8-how-do-i-transform-a-mapk-v-to-another-mapk-v-using-a-lambda – Anshul Singhal Apr 25 '19 at 09:01

1 Answers1

0

Value against owner key is an object. In your object toString() method you can return the name.

@Override
public String toString() {
    return name;
}
Zabuzard
  • 20,717
  • 7
  • 45
  • 67
  • Thanks Guys! I was able to solve this with: yourMap.entrySet().stream().collect(Collectors.toMap(Entry::getKey, e -> e.getValue().getName())); THANKS LINO – Barca Fan Apr 26 '19 at 09:31