Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get key of type UUID and compare to string value

I have a HashMap of type UUID and token. The UUID is the key. I want to get the keys as a String and compare it to another String.
Here my Hashmap :

private final Map<UUID,Token> token = new HashMap<>();

and then I want e.g

token.containsKey(string) = true

but it wont work like this.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

And I want to extract the key value (UUID) and compare it to a string. So it should compare these two. I have tried for loops and with containsKey() but it did not work. Has anyone a solution to this?

Thanks in regard

>Solution :

If I Understand, in a given UUID as a key, you want from it’s String value get it’s Token Value?

So for example:

public boolean isContains(String uuidAsString, Map<UUID, Token> token) {
    UUID key = UUID.fromString(uuidAsString);

    return token.containsKey(key);
}

Pay attention that fromString can throws IllegalArgumentException if name does not conform to the string representation of UUID

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading