So I have a method called indexOf and by specifying a string in main, I can make the program print out the index of that string within the array. But how would I go about simply having a method that can print out the first index of an array, without me needing to specify a string, at all? If the index does not exist, I want it to return -1.
public static void main(String[] args)
{
String[] v = new String[1];
v[0] = "test";
String s = "t";
indexOf(v, s);
}
public static int indexOf(String[] v, String s)
{
int i = v[0].indexOf(s);
System.out.println
("Index of the first string in the first array: " + i);
return -1;
}
}