Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Can you please tell me how to search in reveres order (backward search) in Java?

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

like image 593
Ashish TheCool Avatar asked Jun 01 '11 07:06

Ashish TheCool


1 Answers

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

I assume you mean search for a string starting from the end.

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

The exact same methods exist for StringBuilder as well.

like image 64
aioobe Avatar answered Sep 29 '22 12:09

aioobe