I essentially need to know if I can change 1 arrayList into another arrayList and then make an association as to which item in arrayList 1, an item from arrayList 2 came from, without using a pattern finder. It is difficult to explain, so let illustrate it with a simple example:
Given file input:
Feline:
Cat Lion
Cheetah
Canine:
Dog
Wolves Fox
I split the file into each paragraph using:
String strLine;
String [] paragraph = strLine.split("");
From here I add each item to an arrayList by using an add method inside an advanced for loop.
This should leave us with the first arrayList:
[Feline: Cat Lion Cheetah, Canine: Dog Wolves Fox]
From there in need to split each item into separate words, using the regex \\s+. This should be easy with another advanced for loop.
This should leave us with the second arrayList:
[Feline:, Cat, Lion, Cheetah, Canine:, Dog, Wolves, Fox]
What I need to know is if there anyway for me to get the program to realise that the word Cheetah in the second arrayList originated from the first item in the first arrayList, without having to search the first arraylist for items in the second arrayList. The point has to be that the the one item in the one arrayList originates from the other arrayList.
I essentially need to do this because I have methods that depending what the the first word of each paragraph is, different things are done to each paragraph.
Let me know if my explanation is confusing and sorry about bad terminology, I’m having trouble explaining my problem.
If this is possible please let me know how I might go about solving my problem.
Regards
I would propose to keep the initial array list position when you do the split based on the space character. Say for example you define an object as follows;
Then when you split, you can do something like this;
So now your second list will have an object containing the word as well as the original index it contained in the first list.
Hops this helps.