Results 1 to 3 of 3
  1. #1
    vinoopraj is offline Member
    Join Date
    Mar 2009
    Posts
    15
    Rep Power
    0

    Default HashMap ContainsKey()

    Hi .. all
    I am in trouble with hashmap..
    the code is

    HashMap hash = new HashMap();
    hash.put("ABC", "some values");


    i want to check(hash.containsKey("abc"))
    it returns false...

    thanks in advance
    vinoop

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    So uppercase all your keys when you insert them, and uppercase the string you use when searching for the key.

  3. #3
    arseny is offline Member
    Join Date
    Mar 2009
    Posts
    25
    Rep Power
    0

    Default

    Its because "ABC".equals("abc") returns false.
    If the case is not important you can use one of String.toUpperCase() or String.toLowerCase() method for key in both cases - before putting a key value and before getting it.

Similar Threads

  1. Hashmap to TXT and TXT to Hashmap
    By elvinny in forum Advanced Java
    Replies: 4
    Last Post: 02-16-2011, 11:12 PM
  2. Hashmap - get key according to value
    By gtriant in forum New To Java
    Replies: 1
    Last Post: 12-15-2008, 02:29 PM
  3. Hashmap
    By dirtycash in forum New To Java
    Replies: 5
    Last Post: 12-03-2007, 02:58 AM
  4. what is hashmap
    By gabriel in forum New To Java
    Replies: 5
    Last Post: 08-03-2007, 01:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •