So hi everyone! I've worked with this project to keep a record of a baseball season and I have confront this problem with my ArrayList usage:
. . .
private ArrayList<Team> list1 = new ArrayList<Team>();
Team something = new Team("Somename");
Team somethingelse = new Team("Someothername");
and then I used some setters like:
something.setPoints(1);
somethingelse.setPoints(2);
and then:
list1.add(something);
list1.add(somethingelse);
but here comes the problem:
int help1 = list1.indexOf(something);
System.out.println(help1);
returns -1
but the list contains those objects:
for (Team d: list1) {
System.out.println(d);
}
The output is that toString() -method I wrote to the Team class...
and then I tried it with
ArrayList<Integer> list2 = new ArrayList<Integer>();
list2.add(1);
list2.add(2);
int help2 = list2.indexOf(1);
System.out.println(help2);
returns 0
So basically what I am asking is that is that the right way of using indexOf when the list contains objects which have multiple values?