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<Stringa = new HashSet<String> ();
Map<String, Objectb = 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
case-insensitively? Thus, performing:
a.contains("bob ")
a.contains("BoB ")
a.contains("BOB ")
would all yield the same result?
Thanks for your time. Cheers,
Matt
-- 1 29272
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<Stringa = new HashSet<String> ();
Map<String, Objectb = 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
case-insensitively?
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_INS ENSITIVE_ORDER .
Set<Stringset = new TreeSet<String( String.CASE_INS ENSITIVE_ORDER) ;
// now populate the set
Map<String, Objectmap =
new TreeMap<String, Object>(String. CASE_INSENSITIV E_ORDER);
// now populate the map
Please note that neither TreeSet nor TreeMap are synchronized, so you need
to make them thread-safe yourself.
HTH,
La`ie Techie This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ville Vainio |
last post by:
I need a dict (well, it would be optimal anyway) class that stores the
keys as strings without coercing the case to upper or lower, but still
provides fast lookup (i.e. uses hash table).
>> d = CiDict()
>> d
12
|
by: Madjid Nasiri |
last post by:
Hi,
I am basic in oracle. My Old programs write with Delphi and Databases:
Access, Paradox, MySQL, Microsoft SQL.
I write my code (SQL code) case-insensitivae, but now i need use
oracle database. The Oracle by default is case-sensitive, How can used
case-insensitive in oracle.
Thanks
Madjid Nasiri
|
by: Peter |
last post by:
Hello,
I'm trying to create a case-insensitive hashtable with .NET 2.0, any ideas?
|
by: Relaxin |
last post by:
Is there a way to make Postgresql case-INSENSITIVE?
Thanks
|
by: JohnR |
last post by:
I have an arraylist of string values. I would like to search the arraylist
to find the index of a particular string and I would like the search to be
case insensitive.
dim al as new arraylist
al.add("one")
al.add("two")
dim x as integer = al.indexof("ONE") I would like this to find the match
and return 0
| |
by: Mark Rae |
last post by:
Hi,
In v1.x, I used to use the following code to create a case-insensitive
Hashtable:
Hashtable MyHashtable = new
Hashtable(CaseInsensitiveHashCodeProvider.Default,
CaseInsensitiveComparer.Default);
In v2, this generates the following warnings:
|
by: pamela fluente |
last post by:
Hi
I am doing something like:
Dim MiDict As New System.Collections.Generic.Dictionary(Of String,
MyObject)
how should I change the above so that the string comparison (key) is
done using the case insensitive comparer ?
|
by: benhoefer |
last post by:
I have been searching around and have not been able to find any info
on this. I have a unique situation where I need a case sensitive map:
std::map<string, intimap;
I need to be able to run a find on this map with a case sensitive AND
case insensitive search. I need to be able to change this dynamically
during execution. Is this possible? Any thoughts on this? I
understand that I can make the map case insensitive, but that is not...
|
by: Adrian |
last post by:
Hi,
I want a const static std::set of strings which is case insensitive
for the values.
So I have the following which seems to work but something doesnt seem
right about it. Is there a better way or any gotcha's from my code
below.
|
by: Ethan Furman |
last post by:
Maric Michaud wrote:
Actually, the OP said:
-- So you're saying to ensure that stage_map's keys are initially
-- lower-case to begin with? Well, I can't do this either since the
-- *case of the keys is actually valuable* ***later on***. It's only for
-- the purposes of this specific comparison operation that the case
-- should be ignored.
In other words, the key (as a key) is case-insensitive, and the key (as
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |