Question: I have to plot a graph based on some values.I have to validate whether the values entered are in ascending order.9 textboxes and a submit button is there.
This is a windows application using c#.

If unsorted values are entered ,a message " Enter values in ascending order" should be displayed while clicking submit button.

**Current Code**

```
private void button1_Click(object sender, EventArgs e) 
{ 
    int[] arraynumber = new int[10]; 
    arraynumber[0] = int.Parse(textBox1.Text); 
    arraynumber[1] = int.Parse(textBox2.Text); 
    if (arraynumber[0] > arraynumber[1]) 
    { 
      MessageBox.Show("Enter values in ascending order"); 
    } 
} 

```

Answer: 
The Javadoc states:

> 
> **int java.lang.String.indexOf(String str, int fromIndex)**
> 
> 
> Returns the index within this string of the first occurrence of the specified substring, starting at the specified index. 
> 
> 
> The returned index is the smallest value k for which: 
> 
> 
> 
> ```
> k >= fromIndex && this.startsWith(str, k)
> 
> ```
> 
> If no such value of k exists, then -1 is returned.
> 
> 
> 

If you pass `fromIndex > str.length`, there can be no `k` such that `k >= fromIndex && this.startsWith(str, k)`, so it should return `-1`.

However, as you stated, this is not the implemented behavior. 
`indexOf(String str, int fromIndex)` calls: 

```
static int indexOf(char[] source, int sourceOffset, int sourceCount,
                  char[] target, int targetOffset, int targetCount,
                  int fromIndex)

```

which starts with:

```
if (fromIndex >= sourceCount) {
    return (targetCount == 0 ? sourceCount : -1);
}

```

`targetCount` is the length of the `String` passed to `indexOf`, and `sourceCount` is the length of the `String` on which you call `indexOf`, which means if `fromIndex >= str.length()`, `str.length()` is returned when you call `str.indexOf("",fromIndex)`.

This is either a documentation bug or implementation bug.

BTW, I didn't test this on Android. I tested it on JDK 8.

That said, I would never write code that calls `str.indexOf(subStr,index)` for `index >= str.length()`, since I don't expect `subStr` to be found within `str` in such cases (regardless of whether or not `subStr` is empty).

I would probably never pass an empty `String` to `indexOf` either, since it seems pointless.
In java8, this code:

```
    String s="abcdefg";
    System.out.println(s.indexOf(""));
    System.out.println(s.indexOf("",3));
    System.out.println(s.indexOf("",18);

```

Output:

```
0
3
7

```

in which `7` is the length of `s`. 

While java doc(<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#indexOf-java.lang.String-int->) says:

> 
> public int indexOf(String str,
>  int fromIndex)
> 
> 
> Returns the index within this string of the first occurrence of the
>  specified substring, starting at the specified index.
> 
> 
> The returned index is the smallest value k for which:
> 
> 
> 
> ```
>  k >= fromIndex  && this.startsWith(str, k)
> 
> ```
> 
> If no such value of k exists, then -1 is returned.
> 
> 
> 

So I think there is a doc bug for java8. As I don't know your java version by saying `old version for android`, cann't juedge the situation for that.