ArrayList: Use Set instead of Contains

xiaoxiao2021-03-06  64

In a previous discussion, ArrayList has also pointed out that it is less efficient, it should try to avoid using it! Here is a very practical problem, that is, there is already arraylist, I want to remove the same elements, that is, I hope to get a list!

It also uses two methods here: 1. Generate a new ArrayList, see if it is included in it. 2. Directly take advantage of HashSet (a view of Hashmap) and then return an ArrayList.

Public class test {private static list TestContains (List L) {list list = new arraylist (100); for (int i = 0; i

Private Static List TestSet (List L) {Return New ArrayList (New Hashset (L));

Public Static Void Test (int Total, int CNT) {Long T1, T2; List L = new arraylist (); for (int i = 0; i

T1 = system.currenttimemillis (); for (int i = 0; i

Public static void main (string [] args) {Int total = 100 * 1000; int CNT = 1;

While (CNT

}

Look at the output results:

转载请注明原文地址:https://www.9cbs.com/read-112120.html

New Post(0)