Java array removes repeated method sets, and java array duplicates
It is often used. Sometimes it is not just a simple basic type. The set can be used to remove duplicates. We have used custom types for a lot of time, here is an example (I will use int here ):
Method 1. This is similar to the selection sorting algorithm. First we take the I value and then remove all duplicates after I. The specific implementation is as follows:
Import java. util. list; import java. util. concurrent. copyOnWriteArrayList;/*** Creation Time: 3:26:35 ** @ author zhangtianyou * @ version 2.2 */public class ArrayRemoveRepeat {/*** @ param args */public static void main (String [] args) {// The original array is {, 8, 8,}. The result is }. System. out. println ("previous array"); Integer [] src = {4, 2, 4, 6, 1, 2, 4, 7, 8}; for (Integer k: src) {System. out. print (k + ",") ;}list <Integer> List = new CopyOnWriteArrayList <Integer> (src); int I = 0; while (I <list. size ()-1) {int j = I + 1; while (j <list. size () {if (list. get (I) = list. get (j) {list. remove (j); j --;} j ++;} I ++;} src = list. toArray (new Integer [list. size ()]); System. out. println ("array after \ n"); for (Integer k: src) {System. out. print (k + ",");}}}
Run the following command:
Previous Array
, 8,
Array after
4,2, 6,1, 7,8,