jdk/src/share/classes/java/lang/AbstractStringBuilder.java
changeset 23024 7d5ecb31115f
parent 21334 c60dfce46a77
equal deleted inserted replaced
23023:c1aebf9d16a9 23024:7d5ecb31115f
  1283         return insert(offset, String.valueOf(d));
  1283         return insert(offset, String.valueOf(d));
  1284     }
  1284     }
  1285 
  1285 
  1286     /**
  1286     /**
  1287      * Returns the index within this string of the first occurrence of the
  1287      * Returns the index within this string of the first occurrence of the
  1288      * specified substring. The integer returned is the smallest value
  1288      * specified substring.
  1289      * <i>k</i> such that:
  1289      *
       
  1290      * <p>The returned index is the smallest value {@code k} for which:
  1290      * <pre>{@code
  1291      * <pre>{@code
  1291      * this.toString().startsWith(str, <i>k</i>)
  1292      * this.toString().startsWith(str, k)
  1292      * }</pre>
  1293      * }</pre>
  1293      * is {@code true}.
  1294      * If no such value of {@code k} exists, then {@code -1} is returned.
  1294      *
  1295      *
  1295      * @param   str   any string.
  1296      * @param   str   the substring to search for.
  1296      * @return  if the string argument occurs as a substring within this
  1297      * @return  the index of the first occurrence of the specified substring,
  1297      *          object, then the index of the first character of the first
  1298      *          or {@code -1} if there is no such occurrence.
  1298      *          such substring is returned; if it does not occur as a
       
  1299      *          substring, {@code -1} is returned.
       
  1300      */
  1299      */
  1301     public int indexOf(String str) {
  1300     public int indexOf(String str) {
  1302         return indexOf(str, 0);
  1301         return indexOf(str, 0);
  1303     }
  1302     }
  1304 
  1303 
  1305     /**
  1304     /**
  1306      * Returns the index within this string of the first occurrence of the
  1305      * Returns the index within this string of the first occurrence of the
  1307      * specified substring, starting at the specified index.  The integer
  1306      * specified substring, starting at the specified index.
  1308      * returned is the smallest value {@code k} for which:
  1307      *
       
  1308      * <p>The returned index is the smallest value {@code k} for which:
  1309      * <pre>{@code
  1309      * <pre>{@code
  1310      *     k >= Math.min(fromIndex, this.length()) &&
  1310      *     k >= Math.min(fromIndex, this.length()) &&
  1311      *                   this.toString().startsWith(str, k)
  1311      *                   this.toString().startsWith(str, k)
  1312      * }</pre>
  1312      * }</pre>
  1313      * If no such value of <i>k</i> exists, then -1 is returned.
  1313      * If no such value of {@code k} exists, then {@code -1} is returned.
  1314      *
  1314      *
  1315      * @param   str         the substring for which to search.
  1315      * @param   str         the substring to search for.
  1316      * @param   fromIndex   the index from which to start the 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
  1317      * @return  the index of the first occurrence of the specified substring,
  1318      *          specified substring, starting at the specified index.
  1318      *          starting at the specified index,
       
  1319      *          or {@code -1} if there is no such occurrence.
  1319      */
  1320      */
  1320     public int indexOf(String str, int fromIndex) {
  1321     public int indexOf(String str, int fromIndex) {
  1321         return String.indexOf(value, 0, count, str, fromIndex);
  1322         return String.indexOf(value, 0, count, str, fromIndex);
  1322     }
  1323     }
  1323 
  1324 
  1324     /**
  1325     /**
  1325      * Returns the index within this string of the rightmost occurrence
  1326      * Returns the index within this string of the last occurrence of the
  1326      * of the specified substring.  The rightmost empty string "" is
  1327      * specified substring.  The last occurrence of the empty string "" is
  1327      * considered to occur at the index value {@code this.length()}.
  1328      * considered to occur at the index value {@code this.length()}.
  1328      * The returned index is the largest value <i>k</i> such that
  1329      *
       
  1330      * <p>The returned index is the largest value {@code k} for which:
  1329      * <pre>{@code
  1331      * <pre>{@code
  1330      * this.toString().startsWith(str, k)
  1332      * this.toString().startsWith(str, k)
  1331      * }</pre>
  1333      * }</pre>
  1332      * is true.
  1334      * If no such value of {@code k} exists, then {@code -1} is returned.
  1333      *
  1335      *
  1334      * @param   str   the substring to search for.
  1336      * @param   str   the substring to search for.
  1335      * @return  if the string argument occurs one or more times as a substring
  1337      * @return  the index of the last occurrence of the specified substring,
  1336      *          within this object, then the index of the first character of
  1338      *          or {@code -1} if there is no such occurrence.
  1337      *          the last such substring is returned. If it does not occur as
       
  1338      *          a substring, {@code -1} is returned.
       
  1339      */
  1339      */
  1340     public int lastIndexOf(String str) {
  1340     public int lastIndexOf(String str) {
  1341         return lastIndexOf(str, count);
  1341         return lastIndexOf(str, count);
  1342     }
  1342     }
  1343 
  1343 
  1344     /**
  1344     /**
  1345      * Returns the index within this string of the last occurrence of the
  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>
  1346      * specified substring, searching backward starting at the specified index.
  1347      * such that:
  1347      *
       
  1348      * <p>The returned index is the largest value {@code k} for which:
  1348      * <pre>{@code
  1349      * <pre>{@code
  1349      *     k <= Math.min(fromIndex, this.length()) &&
  1350      *     k <= Math.min(fromIndex, this.length()) &&
  1350      *                   this.toString().startsWith(str, k)
  1351      *                   this.toString().startsWith(str, k)
  1351      * }</pre>
  1352      * }</pre>
  1352      * If no such value of <i>k</i> exists, then -1 is returned.
  1353      * If no such value of {@code k} exists, then {@code -1} is returned.
  1353      *
  1354      *
  1354      * @param   str         the substring to search for.
  1355      * @param   str         the substring to search for.
  1355      * @param   fromIndex   the index to start the search from.
  1356      * @param   fromIndex   the index to start the search from.
  1356      * @return  the index within this sequence of the last occurrence of the
  1357      * @return  the index of the last occurrence of the specified substring,
  1357      *          specified substring.
  1358      *          searching backward from the specified index,
       
  1359      *          or {@code -1} if there is no such occurrence.
  1358      */
  1360      */
  1359     public int lastIndexOf(String str, int fromIndex) {
  1361     public int lastIndexOf(String str, int fromIndex) {
  1360         return String.lastIndexOf(value, 0, count, str, fromIndex);
  1362         return String.lastIndexOf(value, 0, count, str, fromIndex);
  1361     }
  1363     }
  1362 
  1364