On Wed, 14 Mar 2007 22:42:08 -0500, Matt wrote:
> I have to believe I'm not the first person to have this question.
> However, I'm not having any luck finding an answer.
> I'm using Java 1.5. Say I have the following:
> Set<String> a = new HashSet<String>();
> Map<String, Object> b = new TreeMap<String, Object>();
> Assume somewhere these are populated.
> When I check the set for a string using a.contains("bob"), the method is
> checking using a case-sensitive search. Similarly, if I did
> b.containsKey("tom"), it's case-sensitive.
> Is it possible to get these methods to perform a comparison
TreeSet and TreeMap allow you to pass in a Comparator to the constructor.
This Comparator will dictate which objects should be considered equal.
For case-insensitivity, user String.CASE_INSENSITIVE_ORDER .
Set<String> set = new TreeSet<String> (String.CASE_INSENSITIVE_ORDER);
// now populate the set
Map<String, Object> map =
// now populate the map
Please note that neither TreeSet nor TreeMap are synchronized, so you need
to make them thread-safe yourself.