java - Assigning values to Map (Hashmap or Multimap) -


i have map :

hashmap<string, arraylist<integer>> hashmap = new hashmap<string, arraylist<integer>>(); 

after retrieving data remote database server, creating hashmap:(output in eclipse)

{newcomer=[23, 78, 118, 155, 240, 244], zoom=[213], profession=[8, 10, 12, 13, 15]} 

now, concern is, taking of time connect server , download data. size of data beyond limit of patience. there way, can store value directly in hashmap variable (like normal variables, int =5);

in general, how can (like in python) :

hashmap = {newcomer=[23, 78, 118, 155, 240, 244], zoom=[213], profession=[8, 10, 12, 13, 15]} 

i have switched guava recently, can multimap well? value want assign string, assigning might more complicated thinking.

edit 1: need development purpose only. once application live, reconnect database server.

edit 2: have 50k pairs @ moment, hence adding individually not option. may, development, can trim list 100 items, involve labor put each one.

edit 3: understand can figure out someway or other setup database more fast execution. need figure out possible assign? else, going local setup.

inline initialization of maps not possible in java. in case doesn't matter -- amout of data have populating map via code either means hours (or days) of highly repetetive , extremely error-prone manual typing or writing code generator:

i have 50k pairs @ moment, hence adding individually not option.

and if write code generator anyway, doesn't matter if generates inline initializer or loads of map#put() statements.

however, code generation / initialization in code bad choice in case anyway. better solutions (sorted decreasing usefulness):

  • take care of slow database setup or unoptimized query (see comment cbass original question).
  • take care load data once, making delay less relevant big picture.
  • read db server once, serialize file (see objectoutputstream) , deserialize there afterwards.
  • you set local (fast) database server , read instead of remote one.

i wouldn't think of initializing data structure of size in code unless above things have been shown not work. extremely unlikely.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -