How to search in reverse order with String or StringBuilder in Java?

Could you tell me how to search in reveres (reverse search) order in Java?

I need to do the same for searching in an HTML file as text.

+6
source share
2 answers

[...] how to search in reveres order (reverse search) in java?

I assume that you are looking for a line starting at the end.

For this task you can use String.lastIndexOf(str) . This will find the last substring index str . If you want to continue searching from this point, you can add a second fromIndex argument.

Exactly the same methods exist for StringBuilder .

+9
source

if you want to search the file 1. Open the file in random access mode. 2. Go to the end of the file. 3. then do a search on the line.

-1
source

Source: https://habr.com/ru/post/889512/


All Articles