I am trying to write a small method in java, but I cannot figure it out. What I want to do is enter a string, and then the value of the int variable is set to the index of this in the array, i.e. If I have an array consisting of
[0] 'hi guys'
[1] 'this'
[2] 'is'
[3] 'sparta'
The value of my integer is 0, and I want to find the first occurrence of "ta", which will be [3], so I want the function to set my integer to 3.
What I have at the moment is completely off the wall and not so, is there an easy way to do this? I already have a function called get () that returns the value of the current line (i.e. get (0) in this case will return "hello guys"). Can anyone help me out?
Many thanks:)
public void find(String line ) {
boolean found = false;
int i = cursor + 1;
while ( found = false && i!=cursor) {
if ((doc.get(cursor).indexOf( line ) > 0)){
cursor = i;
found = true;
}else {
cursor++;
cursor%=doc.size();
i++;
}
}
}
source
share