src/share/classes/java/lang/AbstractStringBuilder.java

Print this page




1290      * <blockquote><pre>
1291      * this.toString().startsWith(str, <i>k</i>)
1292      * </pre></blockquote>
1293      * is {@code true}.
1294      *
1295      * @param   str   any string.
1296      * @return  if the string argument occurs as a substring within this
1297      *          object, then the index of the first character of the first
1298      *          such substring is returned; if it does not occur as a
1299      *          substring, {@code -1} is returned.
1300      */
1301     public int indexOf(String str) {
1302         return indexOf(str, 0);
1303     }
1304 
1305     /**
1306      * Returns the index within this string of the first occurrence of the
1307      * specified substring, starting at the specified index.  The integer
1308      * returned is the smallest value {@code k} for which:
1309      * <blockquote><pre>
1310      *     k >= Math.min(fromIndex, str.length()) &&
1311      *                   this.toString().startsWith(str, k)
1312      * </pre></blockquote>
1313      * If no such value of <i>k</i> exists, then -1 is returned.
1314      *
1315      * @param   str         the substring for which to search.
1316      * @param   fromIndex   the index from which to start the search.
1317      * @return  the index within this string of the first occurrence of the
1318      *          specified substring, starting at the specified index.
1319      */
1320     public int indexOf(String str, int fromIndex) {
1321         return String.indexOf(value, 0, count, str, fromIndex);
1322     }
1323 
1324     /**
1325      * Returns the index within this string of the rightmost occurrence
1326      * of the specified substring.  The rightmost empty string "" is
1327      * considered to occur at the index value {@code this.length()}.
1328      * The returned index is the largest value <i>k</i> such that
1329      * <blockquote><pre>
1330      * this.toString().startsWith(str, k)
1331      * </pre></blockquote>
1332      * is true.
1333      *
1334      * @param   str   the substring to search for.
1335      * @return  if the string argument occurs one or more times as a substring
1336      *          within this object, then the index of the first character of
1337      *          the last such substring is returned. If it does not occur as
1338      *          a substring, {@code -1} is returned.
1339      */
1340     public int lastIndexOf(String str) {
1341         return lastIndexOf(str, count);
1342     }
1343 
1344     /**
1345      * Returns the index within this string of the last occurrence of the
1346      * specified substring. The integer returned is the largest value <i>k</i>
1347      * such that:
1348      * <blockquote><pre>
1349      *     k <= Math.min(fromIndex, str.length()) &&
1350      *                   this.toString().startsWith(str, k)
1351      * </pre></blockquote>
1352      * If no such value of <i>k</i> exists, then -1 is returned.
1353      *
1354      * @param   str         the substring to search for.
1355      * @param   fromIndex   the index to start the search from.
1356      * @return  the index within this sequence of the last occurrence of the
1357      *          specified substring.
1358      */
1359     public int lastIndexOf(String str, int fromIndex) {
1360         return String.lastIndexOf(value, 0, count, str, fromIndex);
1361     }
1362 
1363     /**
1364      * Causes this character sequence to be replaced by the reverse of
1365      * the sequence. If there are any surrogate pairs included in the
1366      * sequence, these are treated as single characters for the
1367      * reverse operation. Thus, the order of the high-low surrogates
1368      * is never reversed.
1369      *




1290      * <blockquote><pre>
1291      * this.toString().startsWith(str, <i>k</i>)
1292      * </pre></blockquote>
1293      * is {@code true}.
1294      *
1295      * @param   str   any string.
1296      * @return  if the string argument occurs as a substring within this
1297      *          object, then the index of the first character of the first
1298      *          such substring is returned; if it does not occur as a
1299      *          substring, {@code -1} is returned.
1300      */
1301     public int indexOf(String str) {
1302         return indexOf(str, 0);
1303     }
1304 
1305     /**
1306      * Returns the index within this string of the first occurrence of the
1307      * specified substring, starting at the specified index.  The integer
1308      * returned is the smallest value {@code k} for which:
1309      * <blockquote><pre>
1310      *     k >= Math.min(fromIndex, this.length()) &&
1311      *                   this.toString().startsWith(str, k)
1312      * </pre></blockquote>
1313      * If no such value of <i>k</i> exists, then -1 is returned.
1314      *
1315      * @param   str         the substring for which to search.
1316      * @param   fromIndex   the index from which to start the search.
1317      * @return  the index within this string of the first occurrence of the
1318      *          specified substring, starting at the specified index.
1319      */
1320     public int indexOf(String str, int fromIndex) {
1321         return String.indexOf(value, 0, count, str, fromIndex);
1322     }
1323 
1324     /**
1325      * Returns the index within this string of the rightmost occurrence
1326      * of the specified substring.  The rightmost empty string "" is
1327      * considered to occur at the index value {@code this.length()}.
1328      * The returned index is the largest value <i>k</i> such that
1329      * <blockquote><pre>
1330      * this.toString().startsWith(str, k)
1331      * </pre></blockquote>
1332      * is true.
1333      *
1334      * @param   str   the substring to search for.
1335      * @return  if the string argument occurs one or more times as a substring
1336      *          within this object, then the index of the first character of
1337      *          the last such substring is returned. If it does not occur as
1338      *          a substring, {@code -1} is returned.
1339      */
1340     public int lastIndexOf(String str) {
1341         return lastIndexOf(str, count);
1342     }
1343 
1344     /**
1345      * Returns the index within this string of the last occurrence of the
1346      * specified substring. The integer returned is the largest value <i>k</i>
1347      * such that:
1348      * <blockquote><pre>
1349      *     k <= Math.min(fromIndex, this.length()) &&
1350      *                   this.toString().startsWith(str, k)
1351      * </pre></blockquote>
1352      * If no such value of <i>k</i> exists, then -1 is returned.
1353      *
1354      * @param   str         the substring to search for.
1355      * @param   fromIndex   the index to start the search from.
1356      * @return  the index within this sequence of the last occurrence of the
1357      *          specified substring.
1358      */
1359     public int lastIndexOf(String str, int fromIndex) {
1360         return String.lastIndexOf(value, 0, count, str, fromIndex);
1361     }
1362 
1363     /**
1364      * Causes this character sequence to be replaced by the reverse of
1365      * the sequence. If there are any surrogate pairs included in the
1366      * sequence, these are treated as single characters for the
1367      * reverse operation. Thus, the order of the high-low surrogates
1368      * is never reversed.
1369      *