Jo Jo Roid Jo Jo Roid - 1 month ago 10
Android Question

Android - Keep original List Array when distinct it ? Java

I need to have original list of data and changed list of data when I distinct it.

For exmaple :

List<Marketing_Points> userPointList = new ArrayList<>();
userPointList = /*Add a list of data */
Set<Marketing_Points> distinct = new HashSet<>();
distinct.addAll(userPointList);
userPointList.clear();
userPointList.addAll(distinct);


I need to original list and changed list now but I have just changed list of data.What can I do for keep original list?

My
android studio
is
(2.1.2)
and in my
build.gradle(Module.app)
I am using :

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}


And my
JDK
is :

enter image description here

Answer

Simply create a dummy list and add all elements of original list to it and then you can use either of them to create a distinct list(though should use dummy list).

although Set doesn't allow duplicate value so if you have any duplicate value in list then it won't be added to Set(i guess u know this ) so keep a copy of original list to use later

Comments