What I'm Doing
I'm utilizing maps in alot of my code and I find that for efficient sorting and searching, maps are very useful. I like using them because they are the most efficient thing I can think of, being instant lookup.
The problem is
I have alot of things that are simply stored as Strings that I want to be able to look up later. I don't need to store any additional information with these Strings I mostly just want to be able to make a collection where Strings are stored and I can look them up instantly. For example a list of names (I'm using a lot of reflection so having the names of class parameters is an example of what I'm doing.) My question is this, Is there a different collection that allows me to look up the Strings in it without having to store a "value?". I keep making maps where the Key is the value I.E. Map<String,String>
where String key = String value and this seems like a waste of memory. I just want the key anyways there is no need to store a copy of what I want. Surely there must be some functionality I'm not thinking of. I tried a google search for "is using a hashmap with keys that are their values a bad idea?" and I tried searching similar things on stack overflow. Nothing related to this specific problem maybe because I'm being silly and using the wrong thing to store my strings. Either way, the goal is to have a collection that uses less space to hold Strings I can look up. a Hashmap that doesn't have a value because the key is the value. If the key being equal to the value doesn't actually affect the amount of memory used then thats fine but I would think that it does.
ideas of mine
would making a Map<String,null>
work? maybe somehow I could just get the key and since the value would be null that would not use up any extra memory space? I don't know how I would find out what affects memory space and what doesn't.