java - Alternative ways of finding and assigning values in LinkedHashMap inside ArrayList -


i have code displayed below , working fine. wondering if there other ways implement this? doing 4 loops compare , assign new value key of copymatrix linkedhashmap inside arraylist if match found using string/element in seqgenerate. had solution loop wasn't working stuck 1 , wondering if there other ways fewer loops or maybe other techniques.

arraylist<arraylist<string>> seqgenerate = new arraylist<arraylist<string>>(); arraylist<linkedhashmap<string, double>> copyofmatrix = new arraylist<linkedhashmap<string, double>>(); arraylist<linkedhashmap<string, double>> calclogprob = new arraylist<linkedhashmap<string, double>>(); (arraylist<string> getarray: seqgenerate){ linkedhashmap<string, double> tempval = new linkedhashmap<string, double>(); (string getstring: getarray){ (linkedhashmap<string, double> entries: copyofmatrix){ iterator <string> iterkey = entries.keyset().iterator(); iterator <double> iterval = entries.values().iterator(); while (iterkey.hasnext()){ string keyval = iterkey.next(); double value = iterval.next(); if (getstring.equals(keyval)){ double temp = value; if (temp==0){ temp=0.00000001; } double seqval = math.abs(math.log10(temp)); tempval.put(keyval, seqval); } } } } calclogprob.add(tempval); } 

edit

ok trying this: seqgenerate contains elements
arraylist -------- string
(1)hello world = { el ll lo o_ _w wo or rl ld}

(2)hello earth = { el ll lo o_ _e ea ar rt th}

hello world , hello earth example of type of text contained in seqgenerate stored 2 character sequence have illustrated. copyofmatrix contains same kind of sequence generated set of sentences , texts they're sequence of 2 characters going compare , replace value if match found.

so know how compare elements in nested loops make loops example going compare seqgenerate element 0 element 1 keys stored in copy matrix. if found match going replace value. hope clear enough.

thanks time!

i don't understand why you're doing

iterator <string> iterkey = entries.keyset().iterator(); iterator <double> iterval = entries.values().iterator(); while (iterkey.hasnext()){ string keyval = iterkey.next(); double value = iterval.next(); if (getstring.equals(keyval)){ double temp = value; if (temp==0){ temp=0.00000001; } double seqval = math.abs(math.log10(temp)); tempval.put(keyval, seqval); } } 

the whole point of map avoid linear-time traversals. should be

double temp = entries.get(getstring); if (temp != null) { if (temp.doublevalue() == 0) { temp = 0.00000001; } tempval.put(getstring, math.abs(math.log10(temp)); } 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

c++ - Accessing inactive union member and undefined behavior? -

php - Get uncommon values from two or more arrays -