Check it List of objects contains string [duplicate]

This question already has an answer here:

How do I compare strings in Java?

23 answers

What issues should be considered when overriding equals and hashCode in Java?

11 answers

here is my function

private static List getShiftTypes() {

List types = new ArrayList<>();

for (String shift : shifts_arr_t) {

if (!types.contains(shift)) {

types.add(new Types(shift));



return types;



public class Types


String type;

int count;

public Types(String type) {

this.type = type;



public boolean equals(Object object)


boolean sameSame = false;

if (object != null && object instanceof Types)


sameSame = this.type == ((Types) object).type;


return sameSame;



But the compare override is not working. Can you please help me with that?...

Read More »

By: StackOverFlow - Monday, 16 April

Related Posts