I have an array and in this array it contains strings like so:
Contact[] guys = new Contact[8]; guys[0] = new Contact ("Rob", "Smith", "610-555-7384");
This is just an example of course. If I created a linear search how would I output the index location of this particular element (I would test for "Rob", "Smith" and output the index location)? I think the linear search below is what I would need to use but I don't know how to implement the output of the index location in the main method. Any help?
public static int linear(Contact[] list, String target) { int index; for (index=0; index < list.length; index++) if ( target.equals(list[index]) ) return index; return -1; }