Codecademy
codecademy.com › docs › c# › strings › .lastindexof()
C# (C Sharp) | Strings | .LastIndexOf() | Codecademy
May 15, 2024 - The .LastIndexOf() method returns the last occurrence of a specified character or substring within a string.
Videos
07:09
Explain lastIndexOf() method of String Class in Java (Core Java ...
03:22
Java String lastIndexOf() Method | What is lastIndexOf() in Java?
03:07
Java String lastIndexOf() Method | Java String lastIndexOf ...
Java String: How to Use the lastIndexOf(String str, int ...
11:48
indexOf and lastIndexOf String Methods
03:07
JAVA || How to use the .lastIndexOf() string method - YouTube
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › lang › String.html
String (Java SE 17 & JDK 17)
January 20, 2026 - lastIndexOf · (String str) Returns the index within this string of the last occurrence of the specified substring. int · lastIndexOf · (String str, int fromIndex) Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the specified ...
Scaler
scaler.com › topics › lastindexof-in-java
lastIndexOf() in Java - Scaler Topics
May 4, 2023 - The lastIndexOf() method in java returns the last occurrence of a specific character or a specific substring in the string; if the occurrence is not found in the original string, it returns -1.
CodeGym
codegym.cc › java blog › strings in java › java string indexof()
Java String indexOf()
December 26, 2024 - As a Java developer, you must have come across the need to find the position of a character or a substring within a string. Java provides a built-in method called indexOf() in the String class to help us with this task. The indexOf() method in Java is a part of the String class, i.e.
Tutorialspoint
tutorialspoint.com › home › java/lang › java string lastindexof method
Java String lastIndexOf Method
September 1, 2008 - The java.lang.String.lastIndexOf(String str, int fromIndex) method returns the index within this string of the last occurrence of the specified substring, searching backward starting at the specified index.
W3Schools
w3schools.com › java › ref_string_lastindexof.asp
Java String lastIndexOf() Method
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... String myStr = "Hello planet earth, you are a great planet."; System.out.println(myStr.lastIndexOf("planet"));
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-find-the-last-index-of-a-particular-word-in-a-string
Java Program to find the Last Index of a Particular Word in a String - GeeksforGeeks
July 23, 2025 - After initializing with the value now we can use the lastIndexOf() method and should pass the string and word as an argument. After following the above steps then compile the program. Once the program is compiled you will get the output. Example 1: Considering where the character or substring is not present in the string then it will return the last index value. ... // Java Program to find the Last // Index of a particular word // in a string // Importing Classes/Files import java.util.*; public class GFG { // Main driver method public static void main(String[] args) { // String in which char or // substring to be searched String str = "geeksforgeeks"; // Substring to be searched String word = "geeks"; // Printing last index of char // or substring is found // Printing -1 is not found System.out.println(str.lastIndexOf(word)); } }
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › String.html
String (Java Platform SE 8 )
October 20, 2025 - public int lastIndexOf(int ch, int fromIndex) Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index. For values of ch in the range from 0 to 0xFFFF (inclusive), the index returned is the largest value k such ...
GeeksforGeeks
geeksforgeeks.org › java › java-lang-string-lastindexof-method
Java String lastIndexOf() Method with Examples - GeeksforGeeks
November 19, 2024 - The String lastIndexOf() method returns the position of the last occurrence of a given character or substring in a String.
Quora
quora.com › What-is-the-simplest-way-to-get-the-last-two-word-of-a-string-in-Java
What is the simplest way to get the last two word of a string in Java? - Quora
Answer (1 of 3): You can use this: String string = “this is a string ”; String str[] = string.split(‘ ’); System.out.println(“last but one word is “ +str[(str.length-2)】+”last word is” +str[(str.length()-1)】; The former gives the last but one word and the latter the last word.
Top answer 1 of 3
11
From the JavaDoc:
int lastIndexOf(String str, int fromIndex) Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the specified index.
2 of 3
5
Based on the source found here, it appears as if lastIndexOf does traverse from the end of the string, towards the beginning. An excerpt is posted below for convenience; note the decrement operations as it is keeping track of i and j to find the last match.
startSearchForLastChar: while (true) {
while (i >= min && source[i] != strLastChar) {
i--;
}
if (i < min) {
return -1;
}
int j = i - 1;
int start = j - (targetCount - 1);
int k = strLastIndex - 1;
while (j > start) {
if (source[j--] != target[k--]) {
i--;
continue startSearchForLastChar;
}
}
return start - sourceOffset + 1;
}
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › split
String.prototype.split() - JavaScript | MDN
The split() method of String values takes a pattern and divides this string into an ordered list of substrings by searching for the pattern, puts these substrings into an array, and returns the array.
Naukri
naukri.com › code360 › library › string-lastindexof
String, lastIndexOf() - Naukri Code 360
March 27, 2024 - Almost there... just a few more seconds
BeginnersBook
beginnersbook.com › 2013 › 12 › java-string-lastindexof-method-example
Java String lastIndexOf() Method with example
September 11, 2022 - We are looking for their last occurrence in the String str thats why we are using lastIndexOf() method. If you want to find out the first occurrence of a char or substring in a string then using indexOf() method instead. public class JavaExample { public static void main(String[] args) { String str = "beginnersbook is for beginners"; char ch = 'b'; char ch2 = 's'; String subStr = "beginners"; int posOfB = str.lastIndexOf(ch); int posOfS = str.lastIndexOf(ch2); int posOfSubstr = str.lastIndexOf(subStr); System.out.println(posOfB); System.out.println(posOfS); System.out.println(posOfSubstr); } } Output: Here we are demonstrating the use of lastIndexOf() method in various cases.