So I am trying to create a method that finds a title in a ArrayList of photos.
public class Album {
private String albumtitle;
private ArrayList<Photo> photos;
/**
* This constructor should initialize the
* instance variables of the class.
*/
public Album(String title) {
this.albumtitle = title;
photos = new ArrayList<>();
}
This is the code I have got to for trying to search for a specific title of the photo. I am not sure if i should put (int index) or (String title) in the methods parameters.
public Photo searchByTitle(int index) {
if (index >= 0 && index < photos.size()) {
String title = photos.get(index);
System.out.println(title);
}
return null;
}
I am beginner programmer, and I feel a little guidance will help a lot.
Edit: So lots of people are telling me to use for loops. My project requires me to not do for loops for methods, hence why I have displayed it in this way.
I'll give you an example the lecturer gave us:
She doesn't use for loops.