Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6841561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:58:55+00:00 2026-05-26T23:58:55+00:00

I have a requirement where I want to check a map’s value with another

  • 0

I have a requirement where I want to check a map's value with another map's value if it matches I’d like to get the key of 1st map

virtualization map

def virtua=[
    "VMWARE"        :   "00:68:8B:",
    "VMWARE"        :   "00:68:8A",
    "COLINUX"       :   "00:18:8A:"
]

network map

def network=[
    "eth0":"00:68:8B:",
    "eth1":"00:18:8A:",
    "eth2":"00:68:8A:"
]

So after matching values from network & virtua I get the below output, how can i do it in groovy?

eth0,00:68:8B:,VMWARE
eth1,00:18:8A:,COLINUX
eth2,00:68:8A:,VMWARE

Update After @tim_yates & @Xaerxess answer, I thought it’s best if I had MAC Addr as keys as VMWARE can be duplicate

def virtua1=[
"00:68:8B:"     :   "VMWARE",
"00:68:8A:"     :   "VMWARE",
"00:18:8A:"     :   "COLINUX"
]

def coll = network.collect { k, v ->   
    //[ k, v, virtua.find { a, b -> b == v }?.key ]
    print "$k,$v,"
    println virtua1.find{ a, b -> a == v }?.value
}

Output

eth0,00:68:8B:,VMWARE
eth1,00:18:8A:,COLINUX
eth2,00:68:8A:,VMWARE
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:58:56+00:00Added an answer on May 26, 2026 at 11:58 pm

    You can’t have duplicate keys in a map (you have multiple VMWARE entries), and your network variable is a list not a map…

    Correcting these, and assuming you mean:

    def virtua=[
        "VMWAREA"       :   "00:68:8B:",
        "VMWAREB"       :   "00:68:8A:",
        "COLINUX"       :   "00:18:8A:"
    ]
    def network=[
        "eth0":"00:68:8B:",
        "eth1":"00:18:8A:",
        "eth2":"00:68:8A:",
    ]
    

    you can do:

    def coll = network.collect { k, v ->
      [ k, v, virtua.find { a, b -> b == v }?.key ]
    }
    

    To give you the list:

    [ ["eth0", "00:68:8B:", "VMWAREA"],
      ["eth1", "00:18:8A:", "COLINUX"],
      ["eth2", "00:68:8A:", "VMWAREB"] ]
    

    And if you want that printed out as comma separated Strings, you can just do:

    coll*.join(',').each { println it }
    

    Edit — key:list example

    In the comments, I was asked about a Map with values as Lists (to get around the duplicate key problem);

    def virtua=[
        "VMWARE"  : [ "00:68:8B:", "00:68:8A:" ],
        "COLINUX" : [ "00:18:8A:" ]
    ]
    def network=[
        "eth0":"00:68:8B:",
        "eth1":"00:18:8A:",
        "eth2":"00:68:8A:",
    ]
    network.each { k, v ->
      println "$k,$v,${virtua.find { it.value.grep( v ) }?.key}"
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a requirement that I want to check the request headers and according
I have a requirement that i want to get all the system services running
I have a requirement: I want to call method every day at any particular
I have a requirement in sharepoint where I want to Create the top link
My requirement is that I want an object (tee) to update if there have
i have a jquery slider function and i want to customize it. my requirement
I have requirement where some times I would like to load children as well
I have a requirement that before the page is going to load i want
My requirement is on input change i want to check number of non empty
I have the arraylist which has some process names like Notepad, mspaint I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.