how do I sort an array of objects? this is my code for sorting the array, I receive a "not a statement" error for: Movie temp = movies[b]; what do i declare the temp variable as if it is to hold the exact value/reference of movies[b]; which could be any of three different object types which are in the same array? I am new to programming so I apologize if i seem to be ignorant; please feel free to correct me or ask questions if I phrased the questions incorrectly.
public static String bubbleSort(Movie[] movies) {
for (int a=1; a<movies.length; a++) {
for(int b=0; b<movies.length - a; b++) {
if (((movies[b].getTitle()).compareTo((movies[b+1].getTitle()))) > 0)
//swap movies[b] with movies[b+1]
Movie temp = movies[b];
movies[b] = movies[b+1];
movies[b+1] = temp;
}
}
}
ifclause. Without the brackets, only the first statement after the clause -Movie temp = movies[b];- will execute conditionally. The other two statements will always execute.