I'm still pretty green at programming and am running into an issue with the syntax of binary search on an array in Java. I'm trying to invoke a comparator method (overloaded "compare" method) that exists in a separate class from the class that I am using the binary search in. Essentially my goal is to search the array for only one of the variables stored in the object that makes up the array. Without the comparator I have been unsuccessful in doing this as I have created a "dummy" object to hold only the criteria needed for the search as the key.
Here is my code for the binary search:
Song searchSong = new Song(artistInput, artistInput, artistInput);
int search = Arrays.binarySearch(songs, searchSong, new compare<Song>());
This is my code for the overloaded comparator, again, in a separate class:
public int compare (Song firstSong, Song secondSong) {
return firstSong.getArtist().compareTo(secondSong.getArtist());
}
I'm sure it's just something simple I'm missing, but I've yet to find the answer. I appreciate any help and if more specifics are needed, please let me know. I know that the code for the binary search does not work in it's current form.
java.util.Comparator? and 3) All Class Names In Java Begin With Capital Letter