public class UseTheForceExample3
{
public static void main(String args[])
{
// UseTheForceExample3
String force = "Use the force, Luke!";
String findString = "Luke";
int findStringLength = findString.length();
int startIndex = force.indexOf(findString);
int endIndex = startIndex + findStringLength;
String subStr = force.substring(startIndex, endIndex);
System.out.println("Substring is " + subStr);
}
}
Substring is Luke
--- Output Ends ---
- javac UseTheForceExample3.java
- java UseTheForceExample3