Working on a little java program currently, my task is to understand more on how the indexOf method works without actually using the indexOf method. I feel I am close having the code correct. I'll provide my code and my test file. I want to only use the charAt(), length(), and equals() methods for my program.
public class MiniString
{
private String str;
public MiniString(String x)
{
this.str = x;
}
public int findIndexOf(int a)
{
int counter = 0;
for(int i = 0; i < this.str.length(); i++)
{
counter++;
}
char[] arr = new char[counter];
for(int i = 0; i < arr.length; i++)
{
arr[i] = this.str.charAt(i);
}
}
}
Here is what I am passing into my method
public class TestMiniString
{
public static void main(String[] args)
{
MiniString s1 = new MiniString("Hello world, welcome to the Java world.");
System.out.println(s1.findIndexOf('w'));
System.out.println(s1.findIndexOf('m'));
System.out.println(s1.findIndexOf('x'));
System.out.println(s1.findIndexOf('J'));
System.out.println(s1.findIndexOf('a'));
System.out.println();
}