简体   繁体   中英

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.

[...] 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.

if want to search in file 1. Open file in random access mode. 2. go to end of file. 3. then search in string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM