本当の説明は(JavaDocのか、非常に切望されたコードのコメントのいずれかで)は、Javaで指定されていないが、コードを見て、魔法のようです:
呼び出しスタック:
String.indexOf(char[], int, int, char[], int, int, int) line: 1591
String.indexOf(String, int) line: 1564
String.indexOf(String) line: 1546
String.contains(CharSequence) line: 1934
コード:
/**
* Code shared by String and StringBuffer to do searches. The
* source is the character array being searched, and the target
* is the string being searched for.
*
* @param source the characters being searched.
* @param sourceOffset offset of the source string.
* @param sourceCount count of the source string.
* @param target the characters being searched for.
* @param targetOffset offset of the target string.
* @param targetCount count of the target string.
* @param fromIndex the index to begin searching from.
*/
static int indexOf(char[] source, int sourceOffset, int sourceCount,
char[] target, int targetOffset, int targetCount,
int fromIndex) {
if (fromIndex >= sourceCount) {
return (targetCount == 0 ? sourceCount : -1);
}
if (fromIndex < 0) {
fromIndex = 0;
}
if (targetCount == 0) {//my comment: this is where it returns, the size of the
return fromIndex; // incoming string is 0, which is passed in as targetCount
} // fromIndex is 0 as well, as the search starts from the
// start of the source string
...//the rest of the method
出典
2009-06-26 01:37:41
akf
空の文字列に関するいくつかのメソッド: System.out.println( "123" .contains( "")); // true System.out.println( "123" .startsWith( "")); // true System.out.println( "123" .endsWith( "")); // true System.out.println( "123" .indexOf( "")); // 0 するSystem.out.println( "123" .lastIndexOf( "")); // 3 –
空の文字列についてのいくつかのメソッド:
–