I am trying to find if a list contains a string. I have a list object as follows:
Please note this is just example code, to illustrate my point/question!
import java.util.List;
public class FilterByList {
private String actionHero;
private String actionHero2;
private String move;
private int number;
private String actionHero3;
public FilterByList(String actionHero, String actionHero2, String move, int number, String actionHero3) {
this.actionHero = actionHero;
this.actionHero2 = actionHero2;
this.move = move;
this.number = number;
this.actionHero3 = actionHero3;
}
public String getActionHero() {
return actionHero;
}
public void setActionHero(String actionHero) {
this.actionHero = actionHero;
}
public String getActionHero2() {
return actionHero2;
}
public void setActionHero2(String actionHero2) {
this.actionHero2 = actionHero2;
}
public String getMove() {
return move;
}
public void setMove(String move) {
this.move = move;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getActionHero3() {
return actionHero3;
}
public void setActionHero3(String actionHero3) {
this.actionHero3 = actionHero3;
}
}
And then:
public static void main(String[] args) {
List<FilterByList> myList = Collections.singletonList(
new FilterByList("superman", "antman", "ACTION", 123, "batman"));
System.out.println(myList);
if (myList.contains("batman")) {
System.out.println("found it!");
} else {
System.out.println("************************* Did not find anything!!1");
}
}
It does NOT find batman in the list object. So what is printed is the follows:
[com.company.FilterByList@7577b641]
************************* Did not find anything!!1
Any idea how I can:
a) print the contents of the list?
b) find an element in the list with as little code as possible?
Would appreciate your help. Please use my code context to answer as it will give me more pointers.
FilterByListclassmyListcontains only oneFilterByListobject, and this object doesn't equal to"batmat".FilterByListobject?