wood burning stoves 2.0
The moose likes Java in General and the fly likes Store and retrieve Thai Data from HashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Store and retrieve Thai Data from HashMap" Watch "Store and retrieve Thai Data from HashMap" New topic

Store and retrieve Thai Data from HashMap

Sri Ram
Ranch Hand

Joined: Oct 03, 2005
Posts: 118
Hi Ranchers,

I am facing a problem while storing and retrieving thai data in a hashmap. I have both the key and value as thai data. When I want to retrieve value from the hashmap giving the key as thai data, it is not fetching the value. I mean, no value is getting returned even though the data matches. I checked by giving the key as English data, its giving out the result properly.

I understand that there could be a difference while constructing a thai word, where the character sequence can be different. In this case how can I put and get data from a Hashmap.

This is the code example which i am using.

Ådne Brunborg
Ranch Hand

Joined: Aug 05, 2005
Posts: 208
This is what I did to test:

and it generated the following output:
equals: true
equalsIgnoreCase: true
containsKey: true
Should be null: null
Should be something:???

I get a row of "?" instead of the thai characters, most likely since I don't have the character set installed. I don't know why it doesn't work at your end. It should, I think.

Entia non sunt multiplicanda praeter necessitatem
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi ranchers,

perhaps �dne could you please check on your system, what values the question marks really stand for?

I thing the problem has nothing to do with HashMaps but with the encoding.
Sorry, I can't find a solution, but maybe have a look (or two) on this:
i 0 char X value 88
i 1 char Y value 89
i 2 char value 32
i 3 char ? value 63
i 4 char ? value 63
i 5 char ? value 63
i 6 char ? value 63
i 7 char ? value 63
i 8 char ? value 63

All thai letters became int value 63!


At least Cthul where is
Providence Rhode Island

all events occur in real time
Sri Ram
Ranch Hand

Joined: Oct 03, 2005
Posts: 118
Yeah even i was thinking its because of encoding.

My problem is when, i get the value from DB and make the key out of it. I dont know how it is stored in DB. and when i get from Hashmap using this DB data, its coming as null.

Then in that case, how do i put thai data into the hashmap. I dont have any primary key to use also.

Ådne Brunborg
Ranch Hand

Joined: Aug 05, 2005
Posts: 208
Have you tried comparing the two strings - a.equals(b), where a is user input string and b is string read from database? If this returns false (which I think will happen), you should try to make a Key class congtaining the key strings, overriding the equals() method (where you compare the two and "manually" determines if they are equal or not). PS if you override equals you also need to override hashCode().
Sri Ram
Ranch Hand

Joined: Oct 03, 2005
Posts: 118
Thanks all,

I found the problem in file reading. I didnt open the file with UTF-8.
what i was doing is, getting the values from File in normal encoding and puting into the hashmap. These values were going in junk. When i compare with valid thai value, its giving out null.
I agree. Here's the link: http://aspose.com/file-tools
subject: Store and retrieve Thai Data from HashMap
It's not a secret anymore!