I have a code displayed below and its just working fine. But I was wondering if there are other ways to implement this? Basically what I am doing with 4 loops is to compare and assign a new value to Key of CopyMatrix which is a linkedhashmap inside an arraylist if a match is found using the String/Element in SeqGenerate. I had another solution which is also a loop but it wasn’t working so am stuck with this one and am wondering if there are other ways to do this with a fewer loops or maybe some 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>>();
for (ArrayList<String> getArray: SeqGenerate){
LinkedHashMap<String, Double> tempVal = new LinkedHashMap<String, Double>();
for (String getString: getArray){
for (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 what am trying do is like this:
SeqGenerate contains this elements
ArrayList ——– String
(1)Hello World = { He el ll lo o_ _W Wo or rl ld}
(2)Hello Earth = { He el ll lo o_ _E Ea ar rt th}
Hello World and Hello Earth are an example of type of text contained in SeqGenerate but they are stored as two character sequence as I have illustrated.
copyOfMatrix contains the same kind of sequence but i generated it from another set of sentences and texts but they’re always a sequence of two characters that am going to compare and replace the value if a match is found.
So the only I know how to compare elements in nested loops is to make for loops so for example am going to compare seqGenerate element 0 element 1 to the keys stored in copy matrix. If i found a match am going to replace the value. Hope this is clear enough.
Thanks for your time!
I really don’t understand why you’re doing
The whole point of a
Mapis to avoid linear-time traversals. This should just be