I have made a program that reads in an excel file. And then stores certain things in an arrayList and HashMap.
Now I would like to compaire if an value from the arrayList is available in the HashMap.
// Get the keys from the HashMap, mapFile1. Set<Cell> keys = mapFile1.keySet(); // Iterator<Cell> keyIterator = keys.iterator(); // Get the keys from the arrayList (ArrayListFileData2). for (int i = 0; i < ArrayListFileData2.size(); i++) { //System.out.print(ArrayListFileData2.get(i) + " "); // Get the data out of the arrayList. Cell ArrayKey2 = ArrayListFileData2.get(i); //TEST LINE //System.out.println(ArrayKey2); //Change ArrayKey2 to a String. String ArrayKey2String = "" + ArrayKey2; while (keyIterator.hasNext()) { Cell keyObj = keyIterator.next(); //System.out.println( "Key: " + keyObj); String keyObjString = "" + keyObj; //System.out.println("Hallo: " + keyObjString); // Look if there is a match. if (ArrayKey2String.equals(keyObjString)) { System.out.println( "Key: " + keyObj); System.out.println("Ja"); // Write matched keys to an arrayList. ArrayListOutputMatch.add(ArrayKey2String); } else { //System.out.println("Noting found"); } } }
What he does correct:
- Grab every value from the arrayList seperate.
- Grab every key from the LinkedHashMap seperate.
My problem now is:
It only fiends the first word (from the arrayList) in the HashMap.
And not the other ones who come after that.
It looks like the if (ArrayKey2String.equals(keyObjString)) is only being runned one time.
And that is for the first value of the arrayList.
How do I let it run too for the other values?
If I let it print the lines:
//System.out.print(ArrayListFileData2.get(i) + " ");
and
//System.out.println("Hallo: " + keyObjString);
I get as output:
Hallo: Index
Key: Index
Ja
Hallo: 1.0
Hallo: 2.0
Hallo: 3.0
Hallo: 4.0
Hallo: poike
Hallo: kvinna
etc.
So the purple part is made by the if loop.
And the blue part is made in the while loop.
But the other values are also in that HashMap.
Why doesn't that show a match?