Importjava.util.ArrayList;Importjava.util.List;Importorg.junit.Test;/*** Judgment of duplicate data *@authorYangkai **/ Public classDemo {@Test Public voidA () {List<Integer> list =NewArraylist<integer>(); List<Integer> List2 =NewArraylist<integer>(); List.add (1); List.add (1); List.add (2); List.add (2); List.add (2); System.out.println (The length of the list is: "+list.size ()); /*first put the number after the List2 into the*/ for(Integer i:list) {if(!list2.contains (i)) {List2.add (i); } } /*The elements in the list2 are then compared to the elements in the list array, and if they are equal a++*/ for(inti = 0; I < list2.size (); i + +) { intA = 0; for(intj = 0; J < List.size (); J + + ) { if(List2.get (i) = =List.get (j)) {a++; }} System.out.println ("Number" +list2.get (i) + "have:" + + "); } }}
Java EE to judge duplicate data