I have an arrayList in a class and a getter for it. I need to make a method that returns an arrayList filled with all the files from the first arrayList that have the same name as the String arg. This is what I've come up with.
ArrayList<File> dirs = new ArrayList<File>(); // filled with files
public ArrayList<File> getDirectoriesNamed(String fileName) {
ArrayList<File> files = new ArrayList<File>();
for (File file : dirs) {
if (file.getName() == fileName) //problem is here
files.add(file);
}
return files;
}
however when I try this, I get an empty arrayList. and I figured out that the reason is because of the if Statement... is there any reason why that shouldn't work that I'm not seeing?