public MyString1 substring(int begin, int end)
{
char[] charset = new char[end - begin];
while( begin < end)
{
charset[begin] = val[begin];
begin++;
}
return new MyString1(charset);
}
When I try to test out this method in the main method it gives me "Index 2 out of bounds for length 2" error. The size of the array is 5 so how is it that 2 is out of bound?
I used this line to test it
char[] test1 = {'T', 'e', 'S', 't', '1'};
MyString1 s1 = new MyString1(test1);
System.out.println(s1.substring(1, 3));