Java Generate All Key Values For A Map

  
Greenhorn
posted 8 years ago

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
Bartender
posted 8 years ago

Java Map Interface. A map contains values on the basis of key, i.e. Key and value pair. Each key and value pair is known as an entry. A Map contains unique keys. A Map is useful if you have to search, update or delete elements on the basis of a key. Java Map Hierarchy.

A Map is an object that maps keys to values. A map cannot contain duplicate keys: Each key can map to at most one value. It models the mathematical function abstraction. The Map interface includes methods for basic operations (such as put, get, remove, containsKey, containsValue, size, and empty), bulk operations (such as putAll and clear), and collection views (such as keySet, entrySet,. A Map is an object that maps keys to values. A map cannot contain duplicate keys: Each key can map to at most one value. It models the mathematical function abstraction. The Map interface includes methods for basic operations (such as put, get, remove, containsKey, containsValue, size, and empty), bulk operations (such as putAll and clear), and collection views (such as keySet, entrySet,. Jun 22, 2018  The java.util.HashMap.keySet method in Java is used to create a set out of the key elements contained in the hash map. It basically returns a set view of the keys or we can create a new set and store the key elements in them. 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.

  • 1
  1. I would like to create a map that will generate random data( it will generate a random value for each key). I have thought deeply about it but can't get a right answer. I know the sizes for t.
  2. In the previous tutorial we learned about Java Stream Filter.In this guide, we will see how to use Stream filter method to filter a Map by keys and Values. Java 8 – Filter Map by Keys.

Abagesh Kumar wrote:Is it possible to create an hashmap and dynamically populate it ?


Yes.

Java Generate All Key Values For A Map Of Florida


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.

/generate-google-nearby-key-for-android-and-ios.html. 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 /generate-app-key-for-laravel-elastic-beanstalk.html.


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?

Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)

Greenhorn
posted 8 years ago

Java Generate All Key Values For A Map Of America

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
Greenhorn
posted 8 years ago
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]
Bartender
posted 8 years ago

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?
Ranch Hand
posted 12 years ago
Hi,
I am looking to implement a Map, with 1 key and multiple Values for that Key (like may be in a list? ) ..
Can someone give me a rough sketch as to how i can go about it ? (I just need a little skeleton of steps may be ) .. a description of what Entry is and how it works would be great (Java Docs are over loaded =( )..
Thanks in advance guys, appreciate your help!
Vyas, Anirudh

Java Get Value From Map

Ranch Hand

Key Value Pair In Java

posted 12 years ago

I am looking to implement a Map, with 1 key and multiple Values for that Key (like may be in a list? ) ..
Can someone give me a rough sketch as to how i can go about it ? (I just need a little skeleton of steps may be ) .. a description of what Entry is and how it works would be great (Java Docs are over loaded =( )..


You can implement it in this way if i understood you correctly.

You Want it. Get it....the Right Way..<br /> <br />SCJP 5.0 SCWCD 5.0

Ranch Hand
posted 12 years ago

Java Get Key From Value

d-oh thanks, that'll work yea ..
man.. i was looking at this :
http://commons.apache.org/collections/api-release/org/apache/commons/collections/map/MultiValueMap.html
thanks for saving me from the trouble.
Regards
Vyas,Anirudh
Greenhorn

Personal Key Values

posted 10 years ago

Java Get Map Value

MultiValueMap is pretty cool. So easy to just dump a ResultSet into it and not have to worry at all about duplicate keys !.
But I found it somewhat slower. I guess the map operations its doing could be memory intensive.
Before using MultivalueMap I was using the old fashioned way of jdbc loop. Getting back the data one at a time for and putting it into HashMap.
I felt there had to be a better way of doing it, and I stumbled across this post. Even though MultiValueMap does a nice job, I would be interested in seeing,
how much performance would get affected, if my query returned a large resultset.