I have this for loop:
for (int i = 0; i < textParsed.size(); ++i) {
String element = textParsed.get(i);
int readString = 0;
while (savedInput.contains(element)) {
textPositions.add(savedInput.indexOf(element, readString), i);
readString += savedInput.indexOf(element) + element.length();
}
}
Where:
textPositions
is anArrayList<Integer>
textParsed
is anArrayList<String>
It's intended to change textPositions
so that the String
s stored in textParsed
are represented within that ArrayList as numbers.
An example, textParsed
:
["hello", "hi-"]
with the String
:
"hello everyone, hi-hello, it's great to be here, hi-"
should result in a textPositions
of something like:
[0, ... , 1, 0, ... , 1]
Hopefully that makes sense.
I'm getting an IndexOutOfBoundsException when I try to use the .add()
method. As far as I can tell, this should be impossible. Here's the exception:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 29, Size: 1
at java.util.ArrayList.rangeCheckForAdd(ArrayList.java:612)
at java.util.ArrayList.add(ArrayList.java:426)
Thanks for any help you can offer.