printing from an array

if (tempWord.startsWith("'''Loc"))

basically i have code here that prints out the line from an array that starts with loc....

i need to keep printing though. Is there a way i could just start printing from the array when it finds the keyword loc, and print til the end of the array.

eg of text file:

the boy said yes

located the word

then went home

to bed

so here i would start printing at the word location until the end of the array.('bed')

[502 byte] By [trasa] at [2007-11-26 20:30:11]
# 1

Use a for loop with the index declared outside the loop. That way you can access how far into the loop you got when you found "loc". Loop over the array until you find it, then break out of the loop. Start another loop, beginning with the line you ended the other loop with, printing each line until you reach the end of the array.

hunter9000a at 2007-7-10 1:19:44 > top of Java-index,Java Essentials,Java Programming...
# 2

How would you do this manually?

You would keep track of whether you've already seen "loc", and print the item if you had.

pseudo-code:

alreadySawLoc = false

for each item in collection

if item starts with "loc"

alreadySawLoc = true

end if

if alreadySawLoc

print item

end for

warnerjaa at 2007-7-10 1:19:44 > top of Java-index,Java Essentials,Java Programming...
# 3

How about a little method that prints an array starting at element 'loc':public void print(String[] array, int loc) {

for (; loc < array.length; loc++)

System.out.println(array[loc]);

}

kind regards,

Jos

JosAHa at 2007-7-10 1:19:44 > top of Java-index,Java Essentials,Java Programming...