• Post Reply Bookmark Topic Watch Topic
  • New Topic

Create hashmap and dynamically populate  RSS feed

 
Abagesh Kumar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Is it possible to create an hashmap and dynamically populate it ?

How can I do that?

Eg:

I want a hash map created with Keys " A, B , C" with null values ( A B C represent column names of a table)


The values for these keys come from a String parsed by split ( No of strings to be parsed runs into millions) Eg: 123|S|122.14, or S,344,122.146
Strings will be have values for keys (columns) A B C in different positions ( Eg: for 123|S|122.14 - Keys are A B C and for S,123,122.14 kEYS ARE B A C)


I want to bulk load db after maping them to hashmap lists(?) Basically get A=123 B=S C=122.14 using 123|S|122.14 and A=344 B= S and C=122.146 for S,344,122.146 and bulk load fast into a db table


Any ideas

Thanks
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abagesh Kumar wrote:Is it possible to create an hashmap and dynamically populate it ?

Yes.
Abagesh Kumar wrote:How can I do that?

You can write a code which puts key-value pairs in HashMap. I didn't get this question clearly.
Abagesh Kumar wrote:I want a hash map created with Keys " A, B , C" with null values

If values are null anyway, why do you need a Map? It can be done by List as well.
Abagesh Kumar wrote:
The values for these keys come from a String parsed by split ( No of strings to be parsed runs into millions) Eg: 123|S|122.14, or S,344,122.146
Strings will be have values for keys (columns) A B C in different positions ( Eg: for 123|S|122.14 - Keys are A B C and for S,123,122.14 kEYS ARE B A C)

Again, can you please clarify a more? I did not get what this is.
Abagesh Kumar wrote:I want to bulk load db after maping them to hashmap lists

What is 'bulk load db after mapping'? Which mapping? What is 'HashMap Lists'?

Can you please provide more clarification about what exactly are you trying to do? How? And where does HashMap comes into picture?
 
Abagesh Kumar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 4 types of strings which have different delimiters(|, space, <> , comma)

I want to prase them with split . So I will have the substrings in an array

I want to have key=value pairs ( key is column name of table , values are substrings in the strings) ( hashmap comes into picture here) Since keys are same for all the strings( they are not part of the string, I have to map a key to the values which come from the string)

Finally, I want to load these into a db table.
=====================================================
Example Str1, Str2)

123|S|122.14,
S,344,122.146

We can define formats

A|B|C

B|A|C in the program

I want to store the A=123 B=S C=122.14
A=344 B=S C=122.146 ( hashmap)

( mapping the format string with actual value string) and finally load into db

This is the idea I have thought off. But I dont know how to write code for this. Hope I am clearer now.


Please advise Many thanks
 
Abagesh Kumar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a hashmap which will have the keys A , B and C and have position no of substring before the actual string is parsed .

A=2 B= 1 and C=0. Then i am replacing with correct values

But I am getting this exception

A= 2834.56150 B= 1 C 0609
Exception in thread "main" java.lang.NumberFormatException: For input string: "2834.56150"

Please help.

----------------------------------------------------------------------------------



[Added code tags - see UseCodeTags for details]
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abagesh Kumar wrote:
But I am getting this exception

A= 2834.56150 B= 1 C 0609
Exception in thread "main" java.lang.NumberFormatException: For input string: "2834.56150"

You're using Integer.parse(). But 2834.56150 isn't an integer, is it?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!