Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

how to search equalignorecase search with hashmap

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,
I am adding company name in the hash map .I have text box .If user type 'A' or 'a' I have to display 'A' or 'a' company to the user.can anybody tell how to search equalignorecase search in hashmap?

My code

 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Convert to lowercase before adding to the Map
2. Convert the search String to lowercase and search on that.

Or use uppercase for both. Whatever.
 
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to preserve the "case" in Hashmap's Key , then while searching use equalsIgnoreCase(...)
 
vijayakumar durai
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to search equalignorecase on hashmap value can anybody give example I tried but its not working

I am searching value here

 
Marshal
Posts: 69856
278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are adding numbers to the key, you will have to record the numbers, otherwise you will never find the key again. Using "companyname123" as a key looks like bad design to me. In fact it sounds as if you are not using the Map as a Map. Maybe you ought to use a List and simply look for item 123.
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a TreeMap<String>(String.CASE_INSENSITIVE_ORDER). This will use a Comparator<String> that ignores the case. Note that, as the API indicates, this is actually a breach of the Map contract:
I said currently, because it all depends on the way equals is implemented. If the method loops over its own contents and checks if the other map has the same key/value pairs, then you get this. If the method loops over the other map then the output will be reversed.
 
Ganesh Gowtham
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Prime wrote:Use a TreeMap<String>(String.CASE_INSENSITIVE_ORDER). This will use a Comparator<String> that ignores the case. Note that, as the API indicates, this is actually a breach of the Map contract:
I said currently, because it all depends on the way equals is implemented. If the method loops over its own contents and checks if the other map has the same key/value pairs, then you get this. If the method loops over the other map then the output will be reversed.




Hi rob

Map<String,String> map2 = new TreeMap<String,String>(String.CASE_INSENSITIVE_ORDER);

Thanks for showing another way of doing
 
Rob Spoor
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic