Question: I have class: 

```
class MyClass {
    String s1;
    String s2;
}

```

List Object include

> 
> [{s1: "a", s2: "b"}, {s1: "a", s2: "c"}, {s1: "a", s2: "b"}, {s1: "a",
>  s2: "d"}]
> 
> 
> 

I want to remove object duplicate 2 properties s1 and s2 

Expect Result:

> 
> [{s1: "a", s2: "b"}, {s1: "a", s2: "c"}, {s1: "a", s2: "d"}]
> 
> 
> 

If can use Java 8 is better 

Help me :(

Answer: 
First override the `equals` and `hashCode` methods in your `MyClass` like so,

```
@Override
public int hashCode() {
    return 31 * s1.hashCode() + s2.hashCode();
}

@Override
public boolean equals(Object obj) {
    return obj instanceof MyClass && ((MyClass) obj).getS1().equals(getS1())
            && ((MyClass) obj).getS2().equals(getS2());
}

```

Then the easiest way to eliminate duplicates would be using a `Set`.

`new HashSet<>(instances)`
Use like this. 

```
   List<MyClass> listWithoutDuplicates = listWithDuplicates.stream().distinct()
     .collect(Collectors.toList());

```

before using above you need to override equals method in your class

```
    class MyClass {
    String s1;
    String s2;
    @Override
    public int hashCode() {
        return 31 * s1.hashCode() + s2.hashCode();
    }
    @Override
    public boolean equals(Object obj) {

     if(obj instanceof MyClass && ((MyClass) 
        obj).s1.equals(s1)
        && ((MyClass) obj).s2.equals(s2))
       return true;

     return false;
    }
}

```