Directly on the code:
Public Static voidMain (string[] args) {List<Integer> list =NewVector<integer> (20); for(inti = 0; I < 10; i++) {List.add (i% 3); List.add (i% 6); List.add (i# t); List.add (i% 4); } System.out.println ("Original element:" +list); List<Integer> reList =NewVector<integer> (20); for(inti = 0; I < List.size ()-1; i++) { for(intj = i + 1; J < List.size (); J + +) { if(List.get (i) = =List.get (j)) {Relist.add (List.remove (i)); I--; Break; } } }//System.out.println ("Go to Weight after:" + list);//System.out.println ("repeating element:" + reList);//Output://primitive elements: Primitive elements: [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 0, 2, 0, 3, 1, 3, 1, 4, 0, 0, 2, 5, 1, 1, 0, 0, 0, 2, 1, 1, 1, 3, 2, 2, 0, 0, 0, 3, 1, 1]//go back: [4, 5, 2, 0, 3, 1]//repeating elements: [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 0, 2, 0, 3, 1, 3, 1, 0, 0, 2, 1, 1, 0, 0, 0, 2, 1, 1, 1, 3, 2] //de-weight Method 2Set<integer> Intset =NewHashset<integer>(list); System.out.println ("Set to go back" +intset);//Output://primitive elements: [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 0, 2, 0, 3, 1, 3, 1, 4, 0, 0, 2, 5, 1, 1, 0, 0, 0, 2, 1, 1, 1, 3, 2, 2, 0, 0, 0, 3, 1, 1]//set de-weight after [0, 1, 2, 3, 4, 5]//ArrayList<integer> notrelist =NewVector<integer> (20); int[] Intarr =New int[]{1, 2, 4, 5, 6, 3, 4, 2, 3, 4, 34, 5, 23, 5, 2, 3, 4, 3, 3,99}; for(inti = 0; i < intarr.length; i++) {//if not calculated notrelist with I < intarr.length to I < intarr.length-1 if(!notrelist.contains (Intarr[i])) {Notrelist.add (intarr[i]); } for(intj = i + 1; J < Intarr.length; J + +) { if(Intarr[i] = =Intarr[j]) {Relist.add (intarr[i]); Break; }}} System.out.println ("Go to Weight after:" +notrelist); System.out.println ("Repeating element:" +reList);//Output://after weight: [1, 2, 4, 5, 6, 3, (+) , +]//repeating elements: [2, 4, 5, 3, 4, 2, 3, 4, 5, 3, 3]
// The list and array can also be used to turn each other: // List intlist=arrays.aslist (intarr); // integer[] intarr2=new integer[list.size ()]; // List.toarray (INTARR2);
}
Copyright, reproduced Please specify the source: http://www.cnblogs.com/langtianya/p/4676816.html
Find duplicate elements in an existing vector or ArrayList or array & to the existing vector or ArrayList or array