List list uses HashSet to achieve data deduplication tips

In the database, distinct can be used to remove duplicates, but the addition of distinct will affect certain performance. Therefore, in some special cases, where the amount of data is not very large, you can use the characteristics of the java collection Set, the set collection data is not repeated To filter the data

Example code: data filtering, but because the HashSet data is unordered, the data is not sorted

public <T> List<T> distinctListBySet(List<T> list) {
	return new ArrayList<T>(new HashSet<T>(list));

The above code is sorted out of order, and the following code is sorted to check:

public <T> List<T> distinctListBySetOrder(List<T> originList) {
    List<T> newList = new ArrayList<T>();
    Set<T> sortSet = new HashSet<T>();
    for (T entity: originList) {
        if (sortSet.add(entity)) {
    return newList;