• 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Store and retrieve Thai Data from HashMap

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
prints
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!


Yours,
Bu.

---
At least Cthul where is
Providence Rhode Island
 
Sri Ram
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!