I want to compare from a void main method where there is a array and a string. so what I want to do is to compare with if name is in the array. return true else return false. But I cant get it to work. It gives me false on both. And I don't know why?
public boolean isActor(String name) {
if(name.equals(actors)) {
return true;
}else {
return false;
}
}
public static void main(String[] args) {
String[] actors = {"Ulla Skoog", "Suzanne Reuter", "Peter Dalle"} ;
Dvd d1 = new Dvd(10327, "Yrrol", "Peter Dalle", actors, 88);
System.out.println("Medverkar Kalle Kula i Lorry: " + d1.isActor("Kalle kula"));
System.out.println("Medverkar Ulla Skoog i Lorry: " + d1.isActor("Ulla Skoog"));
}
Any help would be appreciated !
EDIT: So I tried to do if(Arrays.asList(actors).contains(name)) and yes it worked. Problem is I might now be allowed to do it under a test which can make me losing points and I tried to make a for loop and by that make a equals statement but still getting the same result which is both false.
EDIT2: Also tried to do this
public boolean isActor(String name) {
for(String s: actors){
if(s.equals(actors))
return true;
}
return false;
}
but still got the same result of both false
EDIT3:
What I want to do is to make e method which is ( public boolean isActor(String name) { ) and with that I want to make a if-statement which should make a algorithm by saying "If this name is on this array. make it say true. If its not in the array. Say its false." Thats what im trying to do.