-2

How can i put data in a HashMap where I don't want duplicate keys like string=a and string=A should be same.

eg:HashMap<String, Integer> map = new HashMap<String, Integer>(); map.put("A", 37); map.put("a", 37);

I want both A and a should be considered same.

leppie
  • 115,091
  • 17
  • 196
  • 297
Lalit
  • 1
  • 2

1 Answers1

0

I guess this is Java

import java.util.HashMap;

public class CaseInsensitiveMap extends HashMap<String, String> {

    @Override
    public String put(String key, String value) {
       return super.put(key.toLowerCase(), value);
    }

    // not @Override because that would require the key parameter to be of type Object
    public String get(String key) {
       return super.get(key.toLowerCase());
    }
}

Soluce by @Vishal Here

Community
  • 1
  • 1
Orelsanpls
  • 22,456
  • 6
  • 42
  • 69