Java Reference
In-Depth Information
Some searches can be very simple. For example, the
String
class and related classes
have methods such as the
indexOf
and
lastIndexOf
methods that can find the oc-
currence of a
String
class. In the simple example that follows, the index of the occur-
rence of the target string is returned by the
indexOf
method:
String text = "Mr. Smith went to 123 Washington avenue.";
String target = "Washington";
int index = text.indexOf(target);
System.out.println(index);
The output of this sequence is shown here:
22