Java Reference
In-Depth Information
Method
Returns Index Of...
lastIndexOf(String str,
int start)
last position of
str
start
The indexing methods that take an
int
parameter for the character to
look for will search for the given character if the value is less than
0xFFFF, or else the code point with the given valuesee "
Working with
If you don't care about the actual index of the substring, you can use
the
contains
method, which returns
TRue
if the current string contains a
given
CharSequence
as a subsequence. If you want to find the index of an
arbitrary
CharSequence
you must invoke
toString
on the
CharSequence
and
pass that to
indexOf
instead.
Exercise 13.1:
Write a method that counts the number of occurrences
of a given character in a string.
Exercise 13.2:
Write a method that counts the number of occurrences
of a particular string in another string.
13.2.2. String Comparisons
The
String
class supports several methods to compare strings and parts
of strings. Before we describe the methods, though, you should be
aware that internationalization and localization issues of full Unicode
strings are not addressed with these methods. For example, when
you're comparing two strings to determine which is "greater," characters
in strings are compared numerically by their Unicode values, not by their
localized notion of order. To a French speaker,
c
and
ç
are the same
letter, differing only by a small diacritical mark. Sorting a set of strings
in French should ignore the difference between them, placing
"açb"
be-