Upload the code First,
1List<String>CriteriaList = new ArrayList<String>();2 Efsncompanycriteria Companycriteria = new Efsncompanycriteria (User.getcompanyid (),3 Efsncompanycriteria. CRITERIA1,4 con);5 Efsncompanycriteria Mpcompanycriteria = new Efsncompanycriteria (User.getcompanyid (),6 Efsncompanycriteria. CRITERIA2,7 con);8 Efsncompanycriteria Seccompanycriteria = new Efsncompanycriteria (User.getcompanyid (),9 Efsncompanycriteria. CRITERIA3,Ten con); One Criterialist.addall (Companycriteria.getlistofplanlevels ()); A Criterialist.addall (Mpcompanycriteria.getlistofplanlevels ()); -Criterialist.addall (Seccompanycriteria.getlistofplanlevels ());
As mentioned above, there may be duplicate values in the 3 criteria that are marked blue, so when we add them all to criterialist, we need to take into account the problem of duplicate values when we show on interface.
Start thinking about it, with the IF (...) {Criterialist.add (...)} Method can be difficult to achieve and error prone.
Then I thought about set (the simplest kind of collection, the objects in the collection are not sorted in a particular way, and there are no duplicate objects .) )
Therefore, the following code block is used to resolve this problem.
1 hashset<string> criterset new hashset<string>(criterialist);
New sets the Set object, and then puts the above criterialist into the inside, although there are duplicate elements in the criterialist, but this time to get
There is no duplicate value in the Criterset, do not know if it is set characteristics (in the internal processing mechanism), tomorrow asked the company of the Great God. 2 criterialist.clear (); 3 Criterialist.addall (Criterset);
Clear () and AddAll ().
Very simple and clear code.
Remove the duplicate values in Java code